Problem
src/routes/proxy.rs:73 allocates a String for every inbound header just to compare against a small blacklist:
for (k, v) in headers.iter() {
let name = k.as_str().to_lowercase();
if matches!(name.as_str(), "host" | "x-api-key" | "content-length") {
continue;
}
req = req.header(k.as_str(), v);
}
HeaderName already normalizes to lowercase internally, and even if it did not, eq_ignore_ascii_case would do the comparison without allocation.
Proposed fix
for (k, v) in headers.iter() {
let name = k.as_str();
if name.eq_ignore_ascii_case("host")
|| name.eq_ignore_ascii_case("x-api-key")
|| name.eq_ignore_ascii_case("content-length")
{
continue;
}
req = req.header(name, v);
}
Or, since http::HeaderName constants exist:
use axum::http::header;
if k == header::HOST || k == header::CONTENT_LENGTH || k.as_str() == "x-api-key" { continue; }
Notes
- Micro-optimization; impact is small but the change is trivial and the current code is misleading.
- Good first issue.
Problem
src/routes/proxy.rs:73allocates aStringfor every inbound header just to compare against a small blacklist:HeaderNamealready normalizes to lowercase internally, and even if it did not,eq_ignore_ascii_casewould do the comparison without allocation.Proposed fix
Or, since
http::HeaderNameconstants exist:Notes