hyper/ext/
informational.rs1use std::sync::Arc;
2
3#[derive(Clone)]
4pub(crate) struct OnInformational(Arc<dyn OnInformationalCallback + Send + Sync>);
5
6pub fn on_informational<B, F>(req: &mut http::Request<B>, callback: F)
21where
22 F: Fn(Response<'_>) + Send + Sync + 'static,
23{
24 on_informational_raw(req, OnInformationalClosure(callback));
25}
26
27pub(crate) fn on_informational_raw<B, C>(req: &mut http::Request<B>, callback: C)
28where
29 C: OnInformationalCallback + Send + Sync + 'static,
30{
31 req.extensions_mut()
32 .insert(OnInformational(Arc::new(callback)));
33}
34
35pub(crate) trait OnInformationalCallback {
37 fn on_informational(&self, res: http::Response<()>);
38}
39
40impl OnInformational {
41 pub(crate) fn call(&self, res: http::Response<()>) {
42 self.0.on_informational(res);
43 }
44}
45
46struct OnInformationalClosure<F>(F);
47
48impl<F> OnInformationalCallback for OnInformationalClosure<F>
49where
50 F: Fn(Response<'_>) + Send + Sync + 'static,
51{
52 fn on_informational(&self, res: http::Response<()>) {
53 let res = Response(&res);
54 (self.0)(res);
55 }
56}
57
58#[derive(Debug)]
69pub struct Response<'a>(&'a http::Response<()>);
70
71impl Response<'_> {
72 #[inline]
73 pub fn status(&self) -> http::StatusCode {
74 self.0.status()
75 }
76
77 #[inline]
78 pub fn version(&self) -> http::Version {
79 self.0.version()
80 }
81
82 #[inline]
83 pub fn headers(&self) -> &http::HeaderMap {
84 self.0.headers()
85 }
86}