sparckles / Robyn

Robyn is a Super Fast Async Python Web Framework with a Rust runtime.
https://robyn.tech/
BSD 2-Clause "Simplified" License
3.9k stars 198 forks source link

feat(tls): support tls version of server #786

Closed iiian closed 2 months ago

iiian commented 2 months ago

Introduce support for HTTP/2 via actix-web.

Addresses: #527

vercel[bot] commented 2 months ago

@iiian is attempting to deploy a commit to the sparckles Team on Vercel.

A member of the Team first needs to authorize it.

iiian commented 2 months ago

So I'm making a draft PR at this point just to share my investigation with code.

Goal: I'm trying to confirm that Python generators with multiple yields are supported, and that HTTP/2 requests with prior knowledge are supported in the scope of #527.

Setups steps

  1. openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost' in the root robyn directory
  2. poetry run maturin develop
  3. poetry run test_server

investigation results

I was able to throw a bunch of http2 requests onto a single tcp channel with

$ curl -kZ \
  https://localhost:8443/yield \
  https://localhost:8443/yield \
  ...
# result is
1+1  1+2  2+3  2+4  3+5  3+6  1+7  1+8  2+9  2+10  3+11  3+12  1+13  1+14  2+15  2+16  3+17  3+18  1+19  1+20  2+21  2+22

Verbose flag confirms its HTTP/2. However, generators with multiple yields on HTTP routes seem to work without HTTP/2 as well. I stripped out all the rustls_0_22 code from server.rs that I added, and went back to regular HTTP/1.1 requests (using listen(raw_socket.into()) just to see if that broke generator functionality (it didn't). So it makes me think that somebody else introduced support for generators.

$ curl -kZ \
  localhost:8080/yield \ #notice that these are all HTTP/1.x requests
  localhost:8080/yield \
  ...
# result is
1+1  1+2  2+3  2+4  3+5  3+6  1+7  1+8  2+9  2+10  3+11  3+12  1+13  1+14  2+15  2+16  3+17  3+18  1+19  1+20  2+21  2+22

@sansyrox given that the ticket is named "support yields" but arbitrary global yields already seem to be working, although conversely given that your comments in #527 allude to integrating prior-knowledge HTTP/2 requests, lets discuss whether you want to close #527 or push for this PR getting cleaned up for HTTP/2 support.

sansyrox commented 2 months ago

Hey @iiian 👋

Thank you for the PR :D I have some comments !