wip: feat: define response body enum
This commit is contained in:
parent
7cb25a7743
commit
008b62a925
12 changed files with 215 additions and 104 deletions
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
error::*,
|
||||
forwarder::{ForwardRequest, Forwarder},
|
||||
globals::Globals,
|
||||
hyper_ext::body::{BoxBody, IncomingLike, IncomingOr},
|
||||
hyper_ext::body::{IncomingLike, IncomingOr, ResponseBody},
|
||||
log::*,
|
||||
name_exp::ServerName,
|
||||
};
|
||||
|
|
@ -58,7 +58,7 @@ where
|
|||
listen_addr: SocketAddr,
|
||||
tls_enabled: bool,
|
||||
tls_server_name: Option<ServerName>,
|
||||
) -> RpxyResult<Response<IncomingOr<BoxBody>>> {
|
||||
) -> RpxyResult<Response<ResponseBody>> {
|
||||
// preparing log data
|
||||
let mut log_data = HttpMessageLog::from(&req);
|
||||
log_data.client_addr(&client_addr);
|
||||
|
|
@ -99,7 +99,7 @@ where
|
|||
listen_addr: SocketAddr,
|
||||
tls_enabled: bool,
|
||||
tls_server_name: Option<ServerName>,
|
||||
) -> HttpResult<Response<IncomingOr<BoxBody>>> {
|
||||
) -> HttpResult<Response<ResponseBody>> {
|
||||
// Here we start to inspect and parse with server_name
|
||||
let server_name = req
|
||||
.inspect_parse_host()
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
use super::http_result::{HttpError, HttpResult};
|
||||
use crate::{
|
||||
error::*,
|
||||
hyper_ext::body::{empty, BoxBody, IncomingOr},
|
||||
hyper_ext::body::{empty, ResponseBody},
|
||||
name_exp::ServerName,
|
||||
};
|
||||
use http::{Request, Response, StatusCode, Uri};
|
||||
|
||||
/// build http response with status code of 4xx and 5xx
|
||||
pub(crate) fn synthetic_error_response(status_code: StatusCode) -> RpxyResult<Response<IncomingOr<BoxBody>>> {
|
||||
pub(crate) fn synthetic_error_response(status_code: StatusCode) -> RpxyResult<Response<ResponseBody>> {
|
||||
let res = Response::builder()
|
||||
.status(status_code)
|
||||
.body(IncomingOr::Right(empty()))
|
||||
.body(ResponseBody::Boxed(empty()))
|
||||
.unwrap();
|
||||
Ok(res)
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ pub(super) fn secure_redirection_response<B>(
|
|||
server_name: &ServerName,
|
||||
tls_port: Option<u16>,
|
||||
req: &Request<B>,
|
||||
) -> HttpResult<Response<IncomingOr<BoxBody>>> {
|
||||
) -> HttpResult<Response<ResponseBody>> {
|
||||
let server_name: String = server_name.try_into().unwrap_or_default();
|
||||
let pq = match req.uri().path_and_query() {
|
||||
Some(x) => x.as_str(),
|
||||
|
|
@ -36,7 +36,7 @@ pub(super) fn secure_redirection_response<B>(
|
|||
let response = Response::builder()
|
||||
.status(StatusCode::MOVED_PERMANENTLY)
|
||||
.header("Location", dest_uri.to_string())
|
||||
.body(IncomingOr::Right(empty()))
|
||||
.body(ResponseBody::Boxed(empty()))
|
||||
.map_err(|e| HttpError::FailedToRedirect(e.to_string()))?;
|
||||
Ok(response)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue