Skip to content

Commit

Permalink
fix disableoverridehost option
Browse files Browse the repository at this point in the history
  • Loading branch information
junkurihara committed Dec 15, 2023
1 parent 47a3f4c commit 1a2a913
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 0.7.0 (unreleased)

- Breaking: `hyper`-1.0 for both server and client modules.
- Breaking: Remove `override_host` option in upstream options. Add a reverse option, i.e., `disable_override_host`. That is, `rpxy` always override the host header by the upstream hostname by default.
- Breaking: Remove `override_host` option in upstream options. Add a reverse option, i.e., `keep_original_host`. That is, `rpxy` always override the host header by the upstream hostname (backend uri host name) by default. If this reverse option specified, original `host` header is maintained or added from the value of url request line.
- Breaking: Introduced `native-tls-backend` feature to use the native TLS engine to access backend applications.
- Redesigned: Cache structure is totally redesigned with more memory-efficient way to read from cache file, and more secure way to strongly bind memory-objects with files with hash values.
- Redesigned: HTTP body handling flow is also redesigned with more memory-and-time efficient techniques without putting the whole objects on memory by using `futures::stream::Stream` and `futures::channel::mpsc`
Expand Down
4 changes: 2 additions & 2 deletions config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ upstream = [
]
load_balance = "round_robin" # or "random" or "sticky" (sticky session) or "none" (fix to the first one, default)
upstream_options = [
"disable_override_host", # do not overwrite HOST value with upstream hostname (like 192.168.xx.x seen from rpxy)
"force_http2_upstream", # mutually exclusive with "force_http11_upstream"
"keep_original_host", # do not overwrite HOST value with upstream hostname (like 192.168.xx.x seen from rpxy)
"force_http2_upstream", # mutually exclusive with "force_http11_upstream"
]

# Non-default destination in "localhost" app, which is routed by "path"
Expand Down
10 changes: 5 additions & 5 deletions rpxy-bin/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub fn init_logger() {

// This limits the logger to emits only proxy crate
let pkg_name = env!("CARGO_PKG_NAME").replace('-', "_");
// let level_string = std::env::var(EnvFilter::DEFAULT_ENV).unwrap_or_else(|_| "info".to_string());
// let filter_layer = EnvFilter::new(format!("{}={}", pkg_name, level_string));
let filter_layer = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new("info"))
.add_directive(format!("{}=trace", pkg_name).parse().unwrap());
let level_string = std::env::var(EnvFilter::DEFAULT_ENV).unwrap_or_else(|_| "info".to_string());
let filter_layer = EnvFilter::new(format!("{}={}", pkg_name, level_string));
// let filter_layer = EnvFilter::try_from_default_env()
// .unwrap_or_else(|_| EnvFilter::new("info"))
// .add_directive(format!("{}=trace", pkg_name).parse().unwrap());

tracing_subscriber::registry()
.with(format_layer)
Expand Down
4 changes: 2 additions & 2 deletions rpxy-lib/src/backend/upstream_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::*;

#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum UpstreamOption {
DisableOverrideHost,
KeepOriginalHost,
UpgradeInsecureRequests,
ForceHttp11Upstream,
ForceHttp2Upstream,
Expand All @@ -12,7 +12,7 @@ impl TryFrom<&str> for UpstreamOption {
type Error = RpxyError;
fn try_from(val: &str) -> RpxyResult<Self> {
match val {
"diaable_override_host" => Ok(Self::DisableOverrideHost),
"keep_original_host" => Ok(Self::KeepOriginalHost),
"upgrade_insecure_requests" => Ok(Self::UpgradeInsecureRequests),
"force_http11_upstream" => Ok(Self::ForceHttp11Upstream),
"force_http2_upstream" => Ok(Self::ForceHttp2Upstream),
Expand Down
2 changes: 1 addition & 1 deletion rpxy-lib/src/forwarder/cache/cache_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl RpxyCache {
.map(|f| {
if f.is_data() {
let data_bytes = f.data_ref().unwrap().clone();
debug!("cache data bytes of {} bytes", data_bytes.len());
// debug!("cache data bytes of {} bytes", data_bytes.len());
// We do not use stream-type buffering since it needs to lock file during operation.
buf.extend(data_bytes.as_ref());
}
Expand Down
7 changes: 4 additions & 3 deletions rpxy-lib/src/message_handler/handler_manipulate_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ where
}
};

let uri = req.uri().to_string();
let original_uri = req.uri().to_string();
let headers = req.headers_mut();
// delete headers specified in header.connection
remove_connection_header(headers);
// delete hop headers including header.connection
remove_hop_header(headers);
// X-Forwarded-For
add_forwarding_header(headers, client_addr, listen_addr, tls_enabled, &uri)?;
add_forwarding_header(headers, client_addr, listen_addr, tls_enabled, &original_uri)?;

// Add te: trailer if te_trailer
if contains_te_trailers {
Expand All @@ -106,6 +106,7 @@ where
.headers_mut()
.insert(header::HOST, HeaderValue::from_str(&org_host)?);
};
let original_host_header = req.headers().get(header::HOST).unwrap().clone();

/////////////////////////////////////////////
// Fix unique upstream destination since there could be multiple ones.
Expand Down Expand Up @@ -135,7 +136,7 @@ where
// by default, host header is overwritten with upstream hostname
override_host_header(headers, &upstream_chosen.uri)?;
// apply upstream options to header
apply_upstream_options_to_header(headers, upstream_candidates)?;
apply_upstream_options_to_header(headers, &original_host_header, upstream_candidates)?;

// update uri in request
ensure!(
Expand Down
9 changes: 5 additions & 4 deletions rpxy-lib/src/message_handler/utils_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,18 @@ pub(super) fn override_host_header(headers: &mut HeaderMap, upstream_base_uri: &
/// Apply options to request header, which are specified in the configuration
pub(super) fn apply_upstream_options_to_header(
headers: &mut HeaderMap,
original_host_header: &HeaderValue,
// _client_addr: &SocketAddr,
upstream: &UpstreamCandidates,
// _upstream_base_uri: &Uri,
) -> Result<()> {
for opt in upstream.options.iter() {
match opt {
UpstreamOption::DisableOverrideHost => {
// simply remove HOST header value
UpstreamOption::KeepOriginalHost => {
// revert hostname
headers
.remove(header::HOST)
.ok_or_else(|| anyhow!("Failed to remove host header in disable_override_host option"))?;
.insert(header::HOST, original_host_header.to_owned())
.ok_or_else(|| anyhow!("Failed to revert host header in keep_original_host option"))?;
}
UpstreamOption::UpgradeInsecureRequests => {
// add upgrade-insecure-requests in request header if not exist
Expand Down
4 changes: 2 additions & 2 deletions rpxy-lib/src/proxy/proxy_h3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ where

if frame.is_data() {
let data = frame.into_data().unwrap_or_default();
debug!("Write data to HTTP/3 stream");
// debug!("Write data to HTTP/3 stream");
send_stream.send_data(data).await?;
} else if frame.is_trailers() {
let trailers = frame.into_trailers().unwrap_or_default();
debug!("Write trailer to HTTP/3 stream");
// debug!("Write trailer to HTTP/3 stream");
send_stream.send_trailers(trailers).await?;
}
}
Expand Down

0 comments on commit 1a2a913

Please sign in to comment.