-
Notifications
You must be signed in to change notification settings - Fork 721
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
docs(s2n-tls-hyper): Add hyper client/server example #5069
base: main
Are you sure you want to change the base?
Conversation
4b5e26a
to
639d791
Compare
639d791
to
d8b1f65
Compare
f84e8eb
to
d8b1f65
Compare
struct Args { | ||
#[clap(short, long, default_value = "localhost:1142")] |
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.
Nit, mostly curious: Why 1142? I'm not sure that's a random choice I've seen before
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.
It's the last part of my phone number :D
``` | ||
cargo run --bin client -- --body "some text to send to the server" | ||
``` |
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 I run the client without the server? Like cargo run --bin client -- --addr "google.com"
?
Right now I think it'd fail because of no echo, but should it maybe just print the response or something instead or asserting the response?
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.
Yes, it'd work on other servers too! That makes sense, I'll remove the assertion.
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 confirmed that it works by testing amazon.com. 🤔
❯ cargo run --bin client -- --addr www.amazon.com
...
</div></body></html>
<!-- _
.__(.)< (MEOW)
\___)
~~~~~~~~~~~~~~~~~~-->
<!-- sp:eh:4jC4pgPb20I/tYlRalVa1l4nPSi6Gt0bZQsubiOGQJlqO8NWckvdYiuBYPNtEiusycvzshYbU3Ch/J3giUKgYFukhBylN1bgfwad0xtHjb+r6Cf25uNOaFnyego= -->
// Enable HTTP/2 by including it in the server's supported ALPN values. The "http2" | ||
// hyper-util feature must also be enabled. | ||
builder.set_application_protocol_preference([b"h2"])?; |
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 remember this was discussed in a previous PR. So we landed on manually setting the alpn via s2n-tls? Idk, this example might make me rethink that choice :/
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.
The ALPN doesn't need to be manually configured with s2n-tls-hyper. It will attempt to negotiate HTTP/2 by automatically setting the ALPN:
s2n-tls/bindings/rust/standard/s2n-tls-hyper/src/connector.rs
Lines 186 to 200 in 3e57b05
// Attempt to negotiate HTTP/2 by including it in the ALPN extension. Other supported HTTP | |
// versions are also included to prevent the server from rejecting the TLS connection if | |
// HTTP/2 isn't supported: | |
// | |
// https://datatracker.ietf.org/doc/html/rfc7301#section-3.2 | |
// In the event that the server supports no | |
// protocols that the client advertises, then the server SHALL respond | |
// with a fatal "no_application_protocol" alert. | |
let builder = connection::ModifiedBuilder::new(self.conn_builder.clone(), |conn| { | |
conn.set_application_protocol_preference([ | |
b"h2".to_vec(), | |
b"http/1.1".to_vec(), | |
b"http/1.0".to_vec(), | |
]) | |
}); |
This is a hyper server example which directly uses s2n-tls-tokio, not s2n-tls-hyper. s2n-tls-hyper is only used with the hyper client.
Resolved issues:
Addresses #5000 (review)
Description of changes:
Adds a client and server example for using s2n-tls with hyper. The example client sends an HTTP request to the server, and the server echos the request body back the client in its response.
Call-outs:
Let me know if I can make anything in the examples more clear!
Testing:
The client/server examples will be built in CI. I ran them locally to make sure they work.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.