New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: ignore upgrade header when no upgrade listener is present #1085
Conversation
Is there any way you can make this not breaking? Maybe an initialization option for automatic upgrading that is true by default? |
Although maybe that's not a great idea if this is correcting behavior. Is this upgrade behavior documented somewhere? |
5228839
to
a54304d
Compare
I've changed the implementation to be more in line with nodejs: The normal The upgrade and connect are special cases since the http codec must be detached. In these cases the 'response' event will not be emitted. If you want to implement websockets, you need to listen for an upgrade request: |
end | ||
if self.method == 'CONNECT' or res.headers.upgrade then | ||
local evt = self.method == 'CONNECT' and 'connect' or 'upgrade' | ||
if self:listenerCount(evt) > 0 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what this count check is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See nodejs http client source.
If you are listening on "upgrade" it means that you expect an upgrade event. If you are not listening on that event, the upgrade header should be ignored. If you are not listening on "upgrade" and the server somehow sends a 101 "switching protocols" then the connection will be destroyed.
Nodejs doc:
Emitted each time a server responds to a request with an upgrade. If this event is not being listened for and the response status code is 101 Switching Protocols, clients receiving an upgrade header will have their connections closed.
141b807
to
342a782
Compare
AppVeyor finally passed. |
Sorry for the lack of attention. I only use coro-http, so the behavior of this module is not something with which I am familiar. If someone else can confirm that this change is sufficiently implemented and non-breaking, we can pull it and maybe bump and release. |
I think this is a worthwhile change. Just ran into it and the current functionality basically creates a silent failure on I think it's worth fixing the 'normal' functionality here (assuming most people are using |
If a server supports HTTP/2 it sends an "Upgrade: h2,h2c" header.
This should be ignored unless the client actually supports HTTP/2.
This is a breaking change for users that depend on the original behaviour.