mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
fix(ext/fetch): set accept-encoding: identity if range header is present (#16197)
https://fetch.spec.whatwg.org/#http-network-or-cache-fetch > If httpRequest’s header list contains `Range`, then append (`Accept-Encoding`, `identity`) > to httpRequest’s header list. > > This avoids a failure when handling content codings with a part of an encoded response. > Additionally, many servers mistakenly ignore `Range` headers if a non-identity encoding is accepted.
This commit is contained in:
parent
698ae4bfed
commit
d0e78ca5c6
@ -34,7 +34,9 @@ use http::header::CONTENT_LENGTH;
|
||||
use reqwest::header::HeaderMap;
|
||||
use reqwest::header::HeaderName;
|
||||
use reqwest::header::HeaderValue;
|
||||
use reqwest::header::ACCEPT_ENCODING;
|
||||
use reqwest::header::HOST;
|
||||
use reqwest::header::RANGE;
|
||||
use reqwest::header::USER_AGENT;
|
||||
use reqwest::redirect::Policy;
|
||||
use reqwest::Body;
|
||||
@ -288,16 +290,26 @@ where
|
||||
None
|
||||
};
|
||||
|
||||
let mut header_map = HeaderMap::new();
|
||||
for (key, value) in headers {
|
||||
let name = HeaderName::from_bytes(&key)
|
||||
.map_err(|err| type_error(err.to_string()))?;
|
||||
let v = HeaderValue::from_bytes(&value)
|
||||
.map_err(|err| type_error(err.to_string()))?;
|
||||
|
||||
if !matches!(name, HOST | CONTENT_LENGTH) {
|
||||
request = request.header(name, v);
|
||||
header_map.append(name, v);
|
||||
}
|
||||
}
|
||||
|
||||
if header_map.contains_key(RANGE) {
|
||||
// https://fetch.spec.whatwg.org/#http-network-or-cache-fetch step 18
|
||||
// If httpRequest’s header list contains `Range`, then append (`Accept-Encoding`, `identity`)
|
||||
header_map
|
||||
.insert(ACCEPT_ENCODING, HeaderValue::from_static("identity"));
|
||||
}
|
||||
request = request.headers(header_map);
|
||||
|
||||
let options = state.borrow::<Options>();
|
||||
if let Some(request_builder_hook) = options.request_builder_hook {
|
||||
request = request_builder_hook(request);
|
||||
|
@ -3266,12 +3266,10 @@
|
||||
"range": {
|
||||
"general.any.html": [
|
||||
"Privileged header not allowed for guard type: request-no-cors",
|
||||
"Fetch with range header will be sent with Accept-Encoding: identity",
|
||||
"Cross Origin Fetch with non safe range header"
|
||||
],
|
||||
"general.any.worker.html": [
|
||||
"Privileged header not allowed for guard type: request-no-cors",
|
||||
"Fetch with range header will be sent with Accept-Encoding: identity",
|
||||
"Cross Origin Fetch with non safe range header"
|
||||
],
|
||||
"general.window.html": false
|
||||
|
Loading…
Reference in New Issue
Block a user