chore: refactor
This commit is contained in:
parent
9fdb378d32
commit
cbd3eb41a1
4 changed files with 34 additions and 29 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
version: "3"
|
|
||||||
services:
|
services:
|
||||||
rpxy-rp:
|
rpxy-rp:
|
||||||
image: jqtype/rpxy:slim # ghcr.io/junkurihara/rust-rpxy:slim also works
|
image: jqtype/rpxy:slim # ghcr.io/junkurihara/rust-rpxy:slim also works
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
version: "3"
|
|
||||||
services:
|
services:
|
||||||
rpxy-rp:
|
rpxy-rp:
|
||||||
image: jqtype/rpxy:latest # ghcr.io/junkurihara/rust-rpxy:latest also works
|
image: jqtype/rpxy:latest # ghcr.io/junkurihara/rust-rpxy:latest also works
|
||||||
|
|
|
||||||
|
|
@ -9,22 +9,36 @@ pub fn init_logger() {
|
||||||
let level_string = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string());
|
let level_string = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string());
|
||||||
let level = tracing::Level::from_str(level_string.as_str()).unwrap_or(tracing::Level::INFO);
|
let level = tracing::Level::from_str(level_string.as_str()).unwrap_or(tracing::Level::INFO);
|
||||||
|
|
||||||
// This limits the logger to emits only this crate with any level, for included crates it will emit only INFO or above level.
|
// This limits the logger to emits only this crate with any level above RUST_LOG, for included crates it will emit only ERROR (in prod)/INFO (in dev) or above level.
|
||||||
let stdio_layer = fmt::layer()
|
let stdio_layer = fmt::layer().with_level(true).with_thread_ids(false);
|
||||||
.with_line_number(true)
|
if level <= tracing::Level::INFO {
|
||||||
.with_thread_ids(false)
|
// in normal deployment environment
|
||||||
.with_thread_names(true)
|
let stdio_layer = stdio_layer
|
||||||
.with_target(true)
|
.with_target(false)
|
||||||
.with_level(true)
|
.compact()
|
||||||
.compact()
|
.with_filter(tracing_subscriber::filter::filter_fn(move |metadata| {
|
||||||
.with_filter(tracing_subscriber::filter::filter_fn(move |metadata| {
|
(metadata
|
||||||
(metadata
|
.target()
|
||||||
.target()
|
.starts_with(env!("CARGO_PKG_NAME").replace('-', "_").as_str())
|
||||||
.starts_with(env!("CARGO_PKG_NAME").replace('-', "_").as_str())
|
&& metadata.level() <= &level)
|
||||||
&& metadata.level() <= &level)
|
|| metadata.level() <= &tracing::Level::ERROR.min(level)
|
||||||
|| metadata.level() <= &tracing::Level::INFO.min(level)
|
}));
|
||||||
}));
|
tracing_subscriber::registry().with(stdio_layer).init();
|
||||||
|
} else {
|
||||||
let reg = tracing_subscriber::registry().with(stdio_layer);
|
// debugging
|
||||||
reg.init();
|
let stdio_layer = stdio_layer
|
||||||
|
.with_line_number(true)
|
||||||
|
.with_target(true)
|
||||||
|
.with_thread_names(true)
|
||||||
|
.with_target(true)
|
||||||
|
.compact()
|
||||||
|
.with_filter(tracing_subscriber::filter::filter_fn(move |metadata| {
|
||||||
|
(metadata
|
||||||
|
.target()
|
||||||
|
.starts_with(env!("CARGO_PKG_NAME").replace('-', "_").as_str())
|
||||||
|
&& metadata.level() <= &level)
|
||||||
|
|| metadata.level() <= &tracing::Level::INFO.min(level)
|
||||||
|
}));
|
||||||
|
tracing_subscriber::registry().with(stdio_layer).init();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,7 @@ where
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
/// Manipulate a response message sent from a backend application to forward downstream to a client.
|
/// Manipulate a response message sent from a backend application to forward downstream to a client.
|
||||||
pub(super) fn generate_response_forwarded<B>(
|
pub(super) fn generate_response_forwarded<B>(&self, response: &mut Response<B>, backend_app: &BackendApp<U>) -> Result<()> {
|
||||||
&self,
|
|
||||||
response: &mut Response<B>,
|
|
||||||
backend_app: &BackendApp<U>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let headers = response.headers_mut();
|
let headers = response.headers_mut();
|
||||||
remove_connection_header(headers);
|
remove_connection_header(headers);
|
||||||
remove_hop_header(headers);
|
remove_hop_header(headers);
|
||||||
|
|
@ -102,11 +98,8 @@ where
|
||||||
// by default, add "host" header of original server_name if not exist
|
// by default, add "host" header of original server_name if not exist
|
||||||
if req.headers().get(header::HOST).is_none() {
|
if req.headers().get(header::HOST).is_none() {
|
||||||
let org_host = req.uri().host().ok_or_else(|| anyhow!("Invalid request"))?.to_owned();
|
let org_host = req.uri().host().ok_or_else(|| anyhow!("Invalid request"))?.to_owned();
|
||||||
req
|
req.headers_mut().insert(header::HOST, HeaderValue::from_str(&org_host)?);
|
||||||
.headers_mut()
|
|
||||||
.insert(header::HOST, HeaderValue::from_str(&org_host)?);
|
|
||||||
};
|
};
|
||||||
println!("{:?}", req.headers().get(header::HOST));
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
// Fix unique upstream destination since there could be multiple ones.
|
// Fix unique upstream destination since there could be multiple ones.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue