support upgrade-insecure-requests option

This commit is contained in:
Jun Kurihara 2022-07-10 04:28:50 +09:00
commit 1a80e405b5
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
8 changed files with 112 additions and 29 deletions

View file

@ -16,13 +16,21 @@ pub(super) fn apply_upstream_options_to_header(
upstream: &Upstream,
) -> Result<()> {
for opt in upstream.opts.iter() {
println!("{:?}", opt);
match opt {
UpstreamOption::OverrideHost => {
// overwrite HOST value with upstream hostname (like 192.168.xx.x seen from rpxy)
let upstream_host = upstream_scheme_host.host().ok_or_else(|| anyhow!("none"))?;
headers
.insert(header::HOST, HeaderValue::from_str(upstream_host)?)
.ok_or_else(|| anyhow!("none"))?;
}
UpstreamOption::UpgradeInsecureRequests => {
// add upgrade-insecure-requests in request header if not exist
headers
.entry(header::UPGRADE_INSECURE_REQUESTS)
.or_insert(HeaderValue::from_bytes(&[b'1']).unwrap());
}
}
}