Skip to content
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

Add special handling for parsing websocket data #73

Closed
wants to merge 1 commit into from

Conversation

sacovo
Copy link
Contributor

@sacovo sacovo commented Feb 5, 2024

Library users can specify when they want to use websocket connections, by setting allow_upgrade to true. If so the parser will send received data to the handler, even when no content-length was specified for the request.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 5, 2024
@mfelsche
Copy link
Contributor

mfelsche commented Feb 5, 2024

Hi @sacovo nice job! Though I would handle the websocket case differently. The protocol itself is not trivial to implement: See for example: https://www.rfc-editor.org/rfc/rfc6455#section-5 And it shouldn't go through the http-parser.

Instead it should be possible to somehow call Session.upgrade(<NEW_HANDLER>) and then this new handler will receive data and will be able to send data to the given connection, including doing websockety stuff. I just need to figure out the details of how this should look.

@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Feb 6, 2024
@sacovo
Copy link
Contributor Author

sacovo commented Feb 7, 2024

Sounds reasonable. I'm working on implementing websocket parsing, I'll let you know, as soon as I finish.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 7, 2024
@sacovo
Copy link
Contributor Author

sacovo commented Feb 10, 2024

I've implemented a parser here: https://github.com/sacovo/flying_pace/blob/main/flying_pace/websocket.pony

@mfelsche
Copy link
Contributor

Sorry for the late reply.

I am in the process of adding a behaviour called upgrade to the Session that takes a TCPConnectionNotify iso and basically just forwards to: TcpConnection.set_notify.

This way one can manually upgrade to whatever protocol is desired. I want to test this with a websocket library that already exists for pony and use its TCPConnectionNotify implementation: https://github.com/oraoto/pony-websocket/blob/master/websocket/listener.pony#L60

Give me another week to finish the tests, but i think it looks promising.

@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2024
@jemc jemc added the do not merge This PR should not be merged at this time label Feb 13, 2024
@jemc
Copy link
Member

jemc commented Feb 13, 2024

Adding the "do not merge" label because this is waiting for the related work from @mfelsche

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2024
@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2024
@mfelsche
Copy link
Contributor

@sacovo I finally got around to finish the session upgrade handling I was talking about in #75 I hope the provided example makes the intent clearer and it works for your websocket needs.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 15, 2024
@sacovo
Copy link
Contributor Author

sacovo commented Feb 16, 2024

Yes, this works (with some small changes).

@sacovo sacovo closed this Feb 16, 2024
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge This PR should not be merged at this time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants