feat: client (wip), still unstable for http2 due to alpn issues

This commit is contained in:
Jun Kurihara 2023-11-28 22:22:40 +09:00
commit a9f5e0ede5
No known key found for this signature in database
GPG key ID: D992B3E3DE1DED23
15 changed files with 199 additions and 70 deletions

View file

@ -1,3 +1,4 @@
use http::Response;
use http_body_util::{combinators, BodyExt, Either, Empty, Full};
use hyper::body::{Bytes, Incoming};
@ -6,6 +7,19 @@ pub(crate) type BoxBody = combinators::BoxBody<Bytes, hyper::Error>;
/// Type for either passthrough body or given body type, specifically synthetic boxed body
pub(crate) type IncomingOr<B> = Either<Incoming, B>;
/// helper function to build http response with passthrough body
pub(crate) fn wrap_incoming_body_response<B>(response: Response<Incoming>) -> Response<IncomingOr<B>>
where
B: hyper::body::Body,
{
response.map(IncomingOr::Left)
}
/// helper function to build http response with synthetic body
pub(crate) fn wrap_synthetic_body_response<B>(response: Response<B>) -> Response<IncomingOr<B>> {
response.map(IncomingOr::Right)
}
/// helper function to build a empty body
pub(crate) fn empty() -> BoxBody {
Empty::<Bytes>::new().map_err(|never| match never {}).boxed()

View file

@ -8,5 +8,7 @@ pub(crate) mod rt {
}
pub(crate) mod body {
pub(crate) use super::body_incoming_like::IncomingLike;
pub(crate) use super::body_type::{empty, full, BoxBody, IncomingOr};
pub(crate) use super::body_type::{
empty, full, wrap_incoming_body_response, wrap_synthetic_body_response, BoxBody, IncomingOr,
};
}