1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

fix(ext/http): error on invalid headers (#14642)

Minor regression/change-in-behaviour from #14552 that filtered out invalid http headers in rust vs error-ing back to JS
This commit is contained in:
Aaron O'Mullan 2022-05-17 14:40:30 +02:00 committed by GitHub
parent 037e46bb51
commit 8879244f72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -518,23 +518,22 @@ async fn op_http_write_headers(
.resource_table
.get::<HttpStreamResource>(rid)?;
let mut builder = Response::builder().status(status);
// Add headers
let header_count = headers.len();
let headers = headers.into_iter().filter_map(|(k, v)| {
let v: Vec<u8> = v.into();
Some((
HeaderName::try_from(k.as_slice()).ok()?,
HeaderValue::try_from(v).ok()?,
))
});
// Track supported encoding
let encoding = *stream.accept_encoding.borrow();
let hmap = builder.headers_mut().unwrap();
hmap.reserve(header_count + 2);
hmap.extend(headers);
let mut builder = Response::builder();
// SAFETY: can not fail, since a fresh Builder is non-errored
let hmap = unsafe { builder.headers_mut().unwrap_unchecked() };
// Add headers
hmap.reserve(headers.len() + 2);
for (k, v) in headers.into_iter() {
let v: Vec<u8> = v.into();
hmap.append(
HeaderName::try_from(k.as_slice())?,
HeaderValue::try_from(v)?,
);
}
ensure_vary_accept_encoding(hmap);
let accepts_compression =
@ -559,7 +558,7 @@ async fn op_http_write_headers(
}
let (new_wr, body) = http_response(data, compressing, encoding)?;
let body = builder.body(body)?;
let body = builder.status(status).body(body)?;
let mut old_wr = RcRef::map(&stream, |r| &r.wr).borrow_mut().await;
let response_tx = match replace(&mut *old_wr, new_wr) {