-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync rama-http-core code with hyperium/hyper v1.6.0
- ext: add ext::on_informational() callback extension (<hyperium/hyper#3818>) (<hyperium/hyper@8ce1fcf>, closes <hyperium/hyper#2565>) - server: add http1::Builder::ignore_invalid_headers(bool) option (<hyperium/hyper#3824>) (<hyperium/hyper@3817a79>) - server: - start http1 header read timeout when conn is idle (<hyperium/hyper#3828>) (<hyperium/hyper@10b09ff>, closes <hyperium/hyper#3780>, <hyperium/hyper#3781>) - change max_local_error_reset_streams function to &mut self (#3820) (e981a91e) - http2::Builder::max_local_error_reset_streams() now takes &mut self and returns &mut Self. In practice, this shouldn't break almost anyone. It was the wrong receiver and return types. (<hyperium/hyper@e981a91>) Co-authored-by: Sean McArthur <[email protected]> Co-authored-by: Finn Bear <[email protected]> Co-authored-by: tottoto <[email protected]>
- Loading branch information
1 parent
c271fe4
commit 764b8a6
Showing
13 changed files
with
234 additions
and
9 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
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,86 @@ | ||
use std::sync::Arc; | ||
|
||
#[derive(Clone)] | ||
pub(crate) struct OnInformational(Arc<dyn OnInformationalCallback + Send + Sync>); | ||
|
||
/// Add a callback for 1xx informational responses. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// # let some_body = (); | ||
/// let mut req = rama_http_types::Request::new(some_body); | ||
/// | ||
/// rama_http_core::ext::on_informational(&mut req, |res| { | ||
/// println!("informational: {:?}", res.status()); | ||
/// }); | ||
/// | ||
/// // send request on a client connection... | ||
/// ``` | ||
pub fn on_informational<B, F>(req: &mut rama_http_types::Request<B>, callback: F) | ||
where | ||
F: Fn(Response<'_>) + Send + Sync + 'static, | ||
{ | ||
on_informational_raw(req, OnInformationalClosure(callback)); | ||
} | ||
|
||
pub(crate) fn on_informational_raw<B, C>(req: &mut rama_http_types::Request<B>, callback: C) | ||
where | ||
C: OnInformationalCallback + Send + Sync + 'static, | ||
{ | ||
req.extensions_mut() | ||
.insert(OnInformational(Arc::new(callback))); | ||
} | ||
|
||
// Sealed, not actually nameable bounds | ||
pub(crate) trait OnInformationalCallback { | ||
fn on_informational(&self, res: rama_http_types::Response<()>); | ||
} | ||
|
||
impl OnInformational { | ||
pub(crate) fn call(&self, res: rama_http_types::Response<()>) { | ||
self.0.on_informational(res); | ||
} | ||
} | ||
|
||
struct OnInformationalClosure<F>(F); | ||
|
||
impl<F> OnInformationalCallback for OnInformationalClosure<F> | ||
where | ||
F: Fn(Response<'_>) + Send + Sync + 'static, | ||
{ | ||
fn on_informational(&self, res: rama_http_types::Response<()>) { | ||
let res = Response(&res); | ||
(self.0)(res); | ||
} | ||
} | ||
|
||
// A facade over rama_http_types::Response. | ||
// | ||
// It purposefully hides being able to move the response out of the closure, | ||
// while also not being able to expect it to be a reference `&Response`. | ||
// (Otherwise, a closure can be written as `|res: &_|`, and then be broken if | ||
// we make the closure take ownership.) | ||
// | ||
// With the type not being nameable, we could change from being a facade to | ||
// being either a real reference, or moving the rama_http_types::Response into the closure, | ||
// in a backwards-compatible change in the future. | ||
#[derive(Debug)] | ||
pub struct Response<'a>(&'a rama_http_types::Response<()>); | ||
|
||
impl Response<'_> { | ||
#[inline] | ||
pub fn status(&self) -> rama_http_types::StatusCode { | ||
self.0.status() | ||
} | ||
|
||
#[inline] | ||
pub fn version(&self) -> rama_http_types::Version { | ||
self.0.version() | ||
} | ||
|
||
#[inline] | ||
pub fn headers(&self) -> &rama_http_types::HeaderMap { | ||
self.0.headers() | ||
} | ||
} |
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 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.