fix server field policy

This commit is contained in:
Jun Kurihara 2022-07-10 12:32:32 +09:00
commit 3a417886d6
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
3 changed files with 19 additions and 8 deletions

View file

@ -179,11 +179,8 @@ where
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);
append_header_entry_with_comma( overwrite_header_entry(headers, "server", env!("CARGO_PKG_NAME"))?;
headers,
"server",
&format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
)?;
#[cfg(feature = "h3")] #[cfg(feature = "h3")]
{ {
if self.globals.http3 { if self.globals.http3 {

View file

@ -16,7 +16,6 @@ pub(super) fn apply_upstream_options_to_header(
upstream: &Upstream, upstream: &Upstream,
) -> Result<()> { ) -> Result<()> {
for opt in upstream.opts.iter() { for opt in upstream.opts.iter() {
println!("{:?}", opt);
match opt { match opt {
UpstreamOption::OverrideHost => { UpstreamOption::OverrideHost => {
// overwrite HOST value with upstream hostname (like 192.168.xx.x seen from rpxy) // overwrite HOST value with upstream hostname (like 192.168.xx.x seen from rpxy)
@ -75,6 +74,23 @@ pub(super) fn add_header_entry_if_not_exist(
Ok(()) Ok(())
} }
pub(super) fn overwrite_header_entry(
headers: &mut HeaderMap,
key: &str,
value: &str,
) -> Result<()> {
match headers.entry(HeaderName::from_bytes(key.as_bytes())?) {
header::Entry::Vacant(entry) => {
entry.insert(value.parse::<HeaderValue>()?);
}
header::Entry::Occupied(mut entry) => {
entry.insert(HeaderValue::from_bytes(value.as_bytes())?);
}
}
Ok(())
}
pub(super) fn add_forwarding_header( pub(super) fn add_forwarding_header(
headers: &mut HeaderMap, headers: &mut HeaderMap,
client_addr: &SocketAddr, client_addr: &SocketAddr,

View file

@ -55,13 +55,11 @@ impl<B> ParseHost for Request<B> {
|| { || {
let m = headers_host.unwrap().as_bytes(); let m = headers_host.unwrap().as_bytes();
if m.starts_with(&[b'[']) { if m.starts_with(&[b'[']) {
println!("v6 bracket");
// v6 address with bracket case. if port is specified, always it is in this case. // v6 address with bracket case. if port is specified, always it is in this case.
let mut iter = m.split(|ptr| ptr == &b'[' || ptr == &b']'); let mut iter = m.split(|ptr| ptr == &b'[' || ptr == &b']');
iter.next().ok_or_else(|| anyhow!("Invalid Host"))?; // first item is always blank iter.next().ok_or_else(|| anyhow!("Invalid Host"))?; // first item is always blank
iter.next().ok_or_else(|| anyhow!("Invalid Host")) iter.next().ok_or_else(|| anyhow!("Invalid Host"))
} else if m.len() - m.split(|v| v == &b':').fold(0, |acc, s| acc + s.len()) >= 2 { } else if m.len() - m.split(|v| v == &b':').fold(0, |acc, s| acc + s.len()) >= 2 {
println!("v6 non-bracket");
// v6 address case, if 2 or more ':' is contained // v6 address case, if 2 or more ':' is contained
Ok(m) Ok(m)
} else { } else {