wip: implementing message handler
This commit is contained in:
parent
e8d67bfc41
commit
a9ce26ae76
16 changed files with 520 additions and 98 deletions
|
|
@ -1,5 +1,3 @@
|
|||
use crate::error::*;
|
||||
use http::{Response, StatusCode};
|
||||
use http_body_util::{combinators, BodyExt, Either, Empty, Full};
|
||||
use hyper::body::{Bytes, Incoming};
|
||||
|
||||
|
|
@ -8,30 +6,8 @@ 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 passthrough_response<B>(response: Response<Incoming>) -> RpxyResult<Response<IncomingOr<B>>>
|
||||
where
|
||||
B: hyper::body::Body,
|
||||
{
|
||||
Ok(response.map(IncomingOr::Left))
|
||||
}
|
||||
|
||||
/// helper function to build http response with synthetic body
|
||||
pub(crate) fn synthetic_response<B>(response: Response<B>) -> RpxyResult<Response<IncomingOr<B>>> {
|
||||
Ok(response.map(IncomingOr::Right))
|
||||
}
|
||||
|
||||
/// build http response with status code of 4xx and 5xx
|
||||
pub(crate) fn synthetic_error_response(status_code: StatusCode) -> RpxyResult<Response<IncomingOr<BoxBody>>> {
|
||||
let res = Response::builder()
|
||||
.status(status_code)
|
||||
.body(IncomingOr::Right(BoxBody::new(empty())))
|
||||
.unwrap();
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// helper function to build a empty body
|
||||
fn empty() -> BoxBody {
|
||||
pub(crate) fn empty() -> BoxBody {
|
||||
Empty::<Bytes>::new().map_err(|never| match never {}).boxed()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,5 @@ pub(crate) mod rt {
|
|||
}
|
||||
pub(crate) mod body {
|
||||
pub(crate) use super::body_incoming_like::IncomingLike;
|
||||
pub(crate) use super::body_type::{BoxBody, IncomingOr};
|
||||
pub(crate) use super::body_type::{empty, full, BoxBody, IncomingOr};
|
||||
}
|
||||
pub(crate) use body_type::{full, passthrough_response, synthetic_error_response, synthetic_response};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue