-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix WebSocket negotiation #4386
Conversation
|
||
listen_port = port_chan.receive | ||
|
||
ws2 = HTTP::WebSocket.new("ws://127.0.0.1:#{listen_port}") |
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.
I consider it a bug that I have to use ws2
to differentiate this variable from ws
above, as that ws is introduced as a block parameter, which should introduce an entirely new variable. If someone from the core team agrees i'll make an issue for this.
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.
I agree, it should not be required to use another variable. It seems that the on_message
in the top is been triggered with the websocket in the bottom. between the two closures that covers ws
and the spawn
there might be something going on.
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.
Besides the two comments, these will be the first specs that runs an HTTP::Server. I am not sure if we were avoiding to do that for some reason: @ysbaddaden / @waj any opinion regarding that?
|
||
listen_port = port_chan.receive | ||
|
||
ws2 = HTTP::WebSocket.new("ws://127.0.0.1:#{listen_port}") |
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.
I agree, it should not be required to use another variable. It seems that the on_message
in the top is been triggered with the websocket in the bottom. between the two closures that covers ws
and the spawn
there might be something going on.
spec/std/http/web_socket_spec.cr
Outdated
ws.on_close do | ||
http_ref.not_nil!.close | ||
end | ||
ws.run |
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.
on the server side there should be no ws.run
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.
Ah thanks, I forgot it did it for me.
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.
Fixed.
I think that specs that run a |
Thanks @RX14 . You were right regarding TCPServer and letting OS choose a port. |
I have also added some specs (with HTTP and HTTPS) for this.