summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2022-03-21 12:56:30 +0100
committerGitHub <noreply@github.com>2022-03-21 12:56:30 +0100
commit45ef3c91c2348560a9a282b44f4b7b8b28929b6f (patch)
treef6db176c0568ef6cc9eff47adced43aee76460c0
parent1414dc503ba4cddcc5fdd5a0417d54678b1ac3fb (diff)
perf(http): avoid per header alloc (#14051)
-rw-r--r--ext/http/lib.rs62
1 files changed, 24 insertions, 38 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index 48a58067e..d636e206c 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -517,50 +517,36 @@ async fn op_http_write_headers(
builder.headers_mut().unwrap().reserve(headers.len());
for (key, value) in &headers {
- match &*key.to_ascii_lowercase() {
- b"cache-control" => {
- if let Ok(value) = std::str::from_utf8(value) {
- if let Some(cache_control) = CacheControl::from_value(value) {
- // We skip compression if the cache-control header value is set to
- // "no-transform"
- if cache_control.no_transform {
- headers_allow_compression = false;
- }
+ if key.eq_ignore_ascii_case(b"cache-control") {
+ if let Ok(value) = std::str::from_utf8(value) {
+ if let Some(cache_control) = CacheControl::from_value(value) {
+ // We skip compression if the cache-control header value is set to
+ // "no-transform"
+ if cache_control.no_transform {
+ headers_allow_compression = false;
}
- } else {
- headers_allow_compression = false;
- }
- }
- b"content-range" => {
- // we skip compression if the `content-range` header value is set, as it
- // indicates the contents of the body were negotiated based directly
- // with the user code and we can't compress the response
- headers_allow_compression = false;
- }
- b"content-type" => {
- if !value.is_empty() {
- content_type_header = Some(value);
}
- }
- b"content-encoding" => {
- // we don't compress if a content-encoding header was provided
+ } else {
headers_allow_compression = false;
}
+ } else if key.eq_ignore_ascii_case(b"content-range") {
+ // we skip compression if the `content-range` header value is set, as it
+ // indicates the contents of the body were negotiated based directly
+ // with the user code and we can't compress the response
+ headers_allow_compression = false;
+ } else if key.eq_ignore_ascii_case(b"content-type") && !value.is_empty() {
+ content_type_header = Some(value);
+ } else if key.eq_ignore_ascii_case(b"content-encoding") {
+ // we don't compress if a content-encoding header was provided
+ headers_allow_compression = false;
+ } else if key.eq_ignore_ascii_case(b"etag") && !value.is_empty() {
// we store the values of ETag and Vary and skip adding them for now, as
// we may need to modify or change.
- b"etag" => {
- if !value.is_empty() {
- etag_header = Some(value);
- continue;
- }
- }
- b"vary" => {
- if !value.is_empty() {
- vary_header = Some(value);
- continue;
- }
- }
- _ => {}
+ etag_header = Some(value);
+ continue;
+ } else if key.eq_ignore_ascii_case(b"vary") && !value.is_empty() {
+ vary_header = Some(value);
+ continue;
}
builder = builder.header(key.as_ref(), value.as_ref());
}