-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to hyper 1. Enable custom + unix listeners.
This commit completely rewrites Rocket's HTTP serving. In addition to significant internal cleanup, this commit introduces the following major features: * Support for custom, external listeners in the `listener` module. The new `listener` module contains new `Bindable`, `Listener`, and `Connection` traits which enable composable, external implementations of connection listeners. Rocket can launch on any `Listener`, or anything that can be used to create a listener (`Bindable`), via a new `launch_on()` method. * Support for Unix domain socket listeners out of the box. The default listener backwards compatibly supports listening on Unix domain sockets. To do so, configure an `address` of `unix:path/to/socket` and optional set `reuse` to `true` (the default) or `false` which controls whether Rocket will handle creating and deleting the unix domain socket. In addition to these new features, this commit makes the following major improvements: * Rocket now depends on hyper 1. * Rocket no longer depends on hyper to handle connections. This allows us to handle more connection failure conditions which results in an overall more robust server with fewer dependencies. * Logic to work around hyper's inability to reference incoming request data in the response results in a 15% performance improvement. * `Client`s can be marked secure with `Client::{un}tracked_secure()`, allowing Rocket to treat local connections as running under TLS. * The `macros` feature of `tokio` is no longer used by Rocket itself. Dependencies can take advantage of this reduction in compile-time cost by disabling the new default feature `tokio-macros`. * A new `TlsConfig::validate()` method allows checking a TLS config. * New `TlsConfig::{certs,key}_reader()`, `MtlsConfig::ca_certs_reader()` methods return `BufReader`s, which allow reading the configured certs and key directly. * A new `NamedFile::open_with()` constructor allows specifying `OpenOptions`. These improvements resulted in the following breaking changes: * The MSRV is now 1.74. * `hyper` is no longer exported from `rocket::http`. * `IoHandler::io` takes `Box<Self>` instead of `Pin<Box<Self>>`. - Use `Box::into_pin(self)` to recover the previous type. * `Response::upgrade()` now returns an `&mut dyn IoHandler`, not `Pin<& mut _>`. * `Config::{address,port,tls,mtls}` methods have been removed. - Use methods on `Rocket::endpoint()` instead. * `TlsConfig` was moved to `tls::TlsConfig`. * `MutualTls` was renamed and moved to `mtls::MtlsConfig`. * `ErrorKind::TlsBind` was removed. * The second field of `ErrorKind::Shutdown` was removed. * `{Local}Request::{set_}remote()` methods take/return an `Endpoint`. * `Client::new()` was removed; it was previously deprecated. Internally, the following major changes were made: * A new `async_bound` attribute macro was introduced to allow setting bounds on futures returned by `async fn`s in traits while maintaining good docs. * All utility functionality was moved to a new `util` module. Resolves #2671. Resolves #1070.
- Loading branch information
1 parent
e9b568d
commit fd29404
Showing
90 changed files
with
3,630 additions
and
3,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use proc_macro2::{TokenStream, Span}; | ||
use devise::{Spanned, Result, ext::SpanDiagnosticExt}; | ||
use syn::{Token, parse_quote, parse_quote_spanned}; | ||
use syn::{TraitItemFn, TypeParamBound, ReturnType, Attribute}; | ||
use syn::punctuated::Punctuated; | ||
use syn::parse::Parser; | ||
|
||
fn _async_bound( | ||
args: proc_macro::TokenStream, | ||
input: proc_macro::TokenStream | ||
) -> Result<TokenStream> { | ||
let bounds = <Punctuated<TypeParamBound, Token![+]>>::parse_terminated.parse(args)?; | ||
if bounds.is_empty() { | ||
return Ok(input.into()); | ||
} | ||
|
||
let mut func: TraitItemFn = syn::parse(input)?; | ||
let original: TraitItemFn = func.clone(); | ||
if !func.sig.asyncness.is_some() { | ||
let diag = Span::call_site() | ||
.error("attribute can only be applied to async fns") | ||
.span_help(func.sig.span(), "this fn declaration must be `async`"); | ||
|
||
return Err(diag); | ||
} | ||
|
||
let doc: Attribute = parse_quote! { | ||
#[doc = concat!( | ||
"# Future Bounds", | ||
"\n", | ||
"**The `Future` generated by this `async fn` must be `", stringify!(#bounds), "`**." | ||
)] | ||
}; | ||
|
||
func.sig.asyncness = None; | ||
func.sig.output = match func.sig.output { | ||
ReturnType::Type(arrow, ty) => parse_quote_spanned!(ty.span() => | ||
#arrow impl ::core::future::Future<Output = #ty> + #bounds | ||
), | ||
default@ReturnType::Default => default | ||
}; | ||
|
||
Ok(quote! { | ||
#[cfg(all(not(doc), rust_analyzer))] | ||
#original | ||
|
||
#[cfg(all(doc, not(rust_analyzer)))] | ||
#doc | ||
#original | ||
|
||
#[cfg(not(any(doc, rust_analyzer)))] | ||
#func | ||
}) | ||
} | ||
|
||
pub fn async_bound( | ||
args: proc_macro::TokenStream, | ||
input: proc_macro::TokenStream | ||
) -> TokenStream { | ||
_async_bound(args, input).unwrap_or_else(|d| d.emit_as_item_tokens()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod entry; | |
pub mod catch; | ||
pub mod route; | ||
pub mod param; | ||
pub mod async_bound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.