mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
perf(http): avoid per header alloc (#14051)
This commit is contained in:
parent
1414dc503b
commit
45ef3c91c2
1 changed files with 24 additions and 38 deletions
|
@ -517,8 +517,7 @@ async fn op_http_write_headers(
|
||||||
|
|
||||||
builder.headers_mut().unwrap().reserve(headers.len());
|
builder.headers_mut().unwrap().reserve(headers.len());
|
||||||
for (key, value) in &headers {
|
for (key, value) in &headers {
|
||||||
match &*key.to_ascii_lowercase() {
|
if key.eq_ignore_ascii_case(b"cache-control") {
|
||||||
b"cache-control" => {
|
|
||||||
if let Ok(value) = std::str::from_utf8(value) {
|
if let Ok(value) = std::str::from_utf8(value) {
|
||||||
if let Some(cache_control) = CacheControl::from_value(value) {
|
if let Some(cache_control) = CacheControl::from_value(value) {
|
||||||
// We skip compression if the cache-control header value is set to
|
// We skip compression if the cache-control header value is set to
|
||||||
|
@ -530,38 +529,25 @@ async fn op_http_write_headers(
|
||||||
} else {
|
} else {
|
||||||
headers_allow_compression = false;
|
headers_allow_compression = false;
|
||||||
}
|
}
|
||||||
}
|
} else if key.eq_ignore_ascii_case(b"content-range") {
|
||||||
b"content-range" => {
|
|
||||||
// we skip compression if the `content-range` header value is set, as it
|
// we skip compression if the `content-range` header value is set, as it
|
||||||
// indicates the contents of the body were negotiated based directly
|
// indicates the contents of the body were negotiated based directly
|
||||||
// with the user code and we can't compress the response
|
// with the user code and we can't compress the response
|
||||||
headers_allow_compression = false;
|
headers_allow_compression = false;
|
||||||
}
|
} else if key.eq_ignore_ascii_case(b"content-type") && !value.is_empty() {
|
||||||
b"content-type" => {
|
|
||||||
if !value.is_empty() {
|
|
||||||
content_type_header = Some(value);
|
content_type_header = Some(value);
|
||||||
}
|
} else if key.eq_ignore_ascii_case(b"content-encoding") {
|
||||||
}
|
|
||||||
b"content-encoding" => {
|
|
||||||
// we don't compress if a content-encoding header was provided
|
// we don't compress if a content-encoding header was provided
|
||||||
headers_allow_compression = false;
|
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 store the values of ETag and Vary and skip adding them for now, as
|
||||||
// we may need to modify or change.
|
// we may need to modify or change.
|
||||||
b"etag" => {
|
|
||||||
if !value.is_empty() {
|
|
||||||
etag_header = Some(value);
|
etag_header = Some(value);
|
||||||
continue;
|
continue;
|
||||||
}
|
} else if key.eq_ignore_ascii_case(b"vary") && !value.is_empty() {
|
||||||
}
|
|
||||||
b"vary" => {
|
|
||||||
if !value.is_empty() {
|
|
||||||
vary_header = Some(value);
|
vary_header = Some(value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
builder = builder.header(key.as_ref(), value.as_ref());
|
builder = builder.header(key.as_ref(), value.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue