fix disableoverridehost option
This commit is contained in:
parent
47a3f4c301
commit
1a2a913256
8 changed files with 22 additions and 20 deletions
|
|
@ -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 {
|
||||
|
|
@ -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.
|
||||
|
|
@ -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!(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue