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 possibility to upgrade the current session to a new TCP handler #75

Merged
merged 14 commits into from
Mar 12, 2024

Conversation

mfelsche
Copy link
Contributor

and add a Websocket example demonstrating this new feature.

and add a Websocket example demonstrating this new feature.
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 15, 2024
@mfelsche mfelsche added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Feb 15, 2024
@@ -0,0 +1,32 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not commit the lock.json? that tends to lead to wtf with tests etc.

is this required? i assume it isn't. (if we do remove, lets add it to the .gitignore)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the example. We can totally keep it out. My thought was that it is usually good practice to include it to improve reproducability of the build of this corral project, as the lock is where the version/git-tag pinning happens.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ive had to do chasing down lock files to find broken builds related to examples that otherwise would have worked. I see your point, its a tough one. They can both lead to pain, the "having lock file" is fresher for pain for me.

@SeanTAllen
Copy link
Member

@mfelsche seems like we should add github.com/mfelsche/pony-websocket as a ponylang project. Are you up for doing that?

@SeanTAllen
Copy link
Member

Or perhaps @mfelsche, would it make sense to incorporate github.com/mfelsche/pony-websocket into this library?

@SeanTAllen SeanTAllen added the do not merge This PR should not be merged at this time label Feb 20, 2024
@SeanTAllen
Copy link
Member

This needs release notes.

Comment on lines 11 to 14
{
"locator": ".",
"revision": "main"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather we use "../" in the use in examples.

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Comment on lines 71 to 79
_session.send_raw(
_response_builder.set_status(StatusSwitchingProtocols)
.add_header("Upgrade", "websocket")
.add_header("Connection", "Upgrade")
.add_header("Sec-WebSocket-Accept", sec_ws_accept)
.finish_headers()
.build(),
request_id
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be integrated be integrated with the _session.upgrade method so that this "Switching Protocols" response will definitely happen (without the user needing to remember to implement this)?

I think it would be better to make this all in one call rather than asking the protocol switching handler to construct a raw response.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are websockets the only reason one would upgrade the session, or might there be other reasons and the header would look different?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade is a general part of the HTTP protocol, so it isn't websocket specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about integrating sending a 101 Response with in the Session.upgrade_protocol function. I initially voted against it, because i wanted to keep the library as raw and low-level as possible. While nearly all protocol upgrades will be used for Websockets, I'd rather not block the path for upgrading to other protocols. And people might want to add special headers to their response and we have multiple API styles used in this library for sending responses, so a generic upgrade_protocol method that does all the upgrading boilerplate while still being generic enough so people can change the response as they see fit, didn't seem worthwile to me.

I'd suggest to move the discussion about a more higher-level API for this to new Issue if need be.

@SeanTAllen
Copy link
Member

If the websocket library isn't a ponylang project then the example shouldnt be part of this repo. The build could be broken by the websocket library falling out of date and maintainers for this package who aren't Matthias wouldn't be able to fix without removing the example.

I think either example goes or we commit to making the websocket library a ponylang project.

IF we go for "example goes", then I think we should take the example and it can be an example repo unto itself OR we can do a blog post on the website after this is released with an example (and perhaps some FAQ fun on the website).

http_server/session.pony Outdated Show resolved Hide resolved
@SeanTAllen
Copy link
Member

@mfelsche for the largest question first so we can move this along, do you want to pull the example out that relies on an external 3rd party library out and use some other location to detail the example or do you want to have the websockets library become a ponylang project that we make sure works with pony language changes going forward?

@sacovo
Copy link
Contributor

sacovo commented Mar 1, 2024

Maybe remove the example for now, and if/when the websocket library is a ponylang project it can be added back in?

@mfelsche
Copy link
Contributor Author

mfelsche commented Mar 1, 2024

Sorry for the late reply. In order to move this forward, lets for now move this example out. I will improve the documentation of the upgrade_protocol behaviour. @sacovo Does this as is solve your use case for websocket support?

@sacovo
Copy link
Contributor

sacovo commented Mar 1, 2024

Yes, it does. Thank you for your work!

mfelsche added 7 commits March 2, 2024 21:36
for representing the HTTP version as 8 byte number for faster comparison during parsing.
stdlib first, external packages second.
Alphabetical order in each section.
Makefile Outdated
Comment on lines 43 to 44
EXAMPLES := $(notdir $(shell find $(EXAMPLES_DIR)/* -maxdepth 0 -type d -not -name websocket_echo_server))
EXAMPLES_SOURCE_FILES := $(shell find $(EXAMPLES_DIR) -name *.pony -not -path '**/websocket_echo_server/*')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be rolled back to how it was previously.

Comment on lines 1 to 6
use "net"
use "collections"
use "valbytes"
use "debug"
use "net"
use "time"

use "valbytes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled bacl

Comment on lines 1 to 2
use "net"
use "debug"
use "net"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

Comment on lines 1 to 2
use "pony_check"
use "pony_test"
use "net"
use "buffered"
use "collections"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

@@ -1,5 +1,5 @@
use "pony_test"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

@@ -1,6 +1,7 @@
use "debug"
use "pony_check"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

@@ -1,7 +1,8 @@
use "net"
use "time"
use "pony_test"
use "random"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

@@ -1,6 +1,7 @@
use "debug"
use "itertools"
use "pony_test"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be rolled back

Comment on lines 1 to 4
use "valbytes"
use "debug"

use "valbytes"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

Comment on lines 1 to 5
use "valbytes"
use "format"

use "valbytes"

interface val Response is ByteSeqIter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

Comment on lines 1 to 5
use "collections"
use "debug"
use "net"
use "net_ssl"
use "time"
use "debug"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

Comment on lines 1 to 4
use "valbytes"
use "debug"

use "valbytes"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated at this point, no new uses were added so I think this should be rolled back

@SeanTAllen SeanTAllen removed the do not merge This PR should not be merged at this time label Mar 5, 2024
@SeanTAllen SeanTAllen merged commit 0983542 into main Mar 12, 2024
7 checks passed
@SeanTAllen SeanTAllen deleted the session_upgrade branch March 12, 2024 18:06
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Mar 12, 2024
github-actions bot pushed a commit that referenced this pull request Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - added Automatically add "Added" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants