mirror of
https://github.com/denoland/deno.git
synced 2025-01-18 03:44:05 -05:00
fix(op_crates/fetch): support non-ascii response headers value (#8600)
This commit is contained in:
parent
b200e6fc3e
commit
d492fb0eac
3 changed files with 40 additions and 2 deletions
|
@ -685,6 +685,20 @@ unitTest(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
unitTest(
|
||||||
|
{
|
||||||
|
perms: { net: true },
|
||||||
|
},
|
||||||
|
async function fetchWithNonAsciiRedirection(): Promise<void> {
|
||||||
|
const response = await fetch("http://localhost:4545/non_ascii_redirect", {
|
||||||
|
redirect: "manual",
|
||||||
|
});
|
||||||
|
assertEquals(response.status, 301);
|
||||||
|
assertEquals(response.headers.get("location"), "/redirect®");
|
||||||
|
await response.text();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
unitTest(
|
unitTest(
|
||||||
{
|
{
|
||||||
perms: { net: true },
|
perms: { net: true },
|
||||||
|
|
|
@ -156,7 +156,20 @@ where
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let mut res_headers = Vec::new();
|
let mut res_headers = Vec::new();
|
||||||
for (key, val) in res.headers().iter() {
|
for (key, val) in res.headers().iter() {
|
||||||
res_headers.push((key.to_string(), val.to_str().unwrap().to_owned()));
|
let key_string = key.to_string();
|
||||||
|
|
||||||
|
if val.as_bytes().is_ascii() {
|
||||||
|
res_headers.push((key_string, val.to_str().unwrap().to_owned()))
|
||||||
|
} else {
|
||||||
|
res_headers.push((
|
||||||
|
key_string,
|
||||||
|
val
|
||||||
|
.as_bytes()
|
||||||
|
.iter()
|
||||||
|
.map(|&c| c as char)
|
||||||
|
.collect::<String>(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rid = state
|
let rid = state
|
||||||
|
|
|
@ -290,6 +290,16 @@ pub async fn run_all_servers() {
|
||||||
*res.status_mut() = StatusCode::FOUND;
|
*res.status_mut() = StatusCode::FOUND;
|
||||||
Box::new(res)
|
Box::new(res)
|
||||||
});
|
});
|
||||||
|
let non_ascii_redirect =
|
||||||
|
warp::path("non_ascii_redirect").map(|| -> Box<dyn Reply> {
|
||||||
|
let mut res = Response::new(Body::empty());
|
||||||
|
*res.status_mut() = StatusCode::MOVED_PERMANENTLY;
|
||||||
|
res.headers_mut().insert(
|
||||||
|
"location",
|
||||||
|
HeaderValue::from_bytes(b"/redirect\xae").unwrap(),
|
||||||
|
);
|
||||||
|
Box::new(res)
|
||||||
|
});
|
||||||
|
|
||||||
let etag_script = warp::path!("etag_script.ts")
|
let etag_script = warp::path!("etag_script.ts")
|
||||||
.and(warp::header::optional::<String>("if-none-match"))
|
.and(warp::header::optional::<String>("if-none-match"))
|
||||||
|
@ -444,7 +454,8 @@ pub async fn run_all_servers() {
|
||||||
.or(echo_server)
|
.or(echo_server)
|
||||||
.or(echo_multipart_file)
|
.or(echo_multipart_file)
|
||||||
.or(multipart_form_data)
|
.or(multipart_form_data)
|
||||||
.or(bad_redirect);
|
.or(bad_redirect)
|
||||||
|
.or(non_ascii_redirect);
|
||||||
|
|
||||||
let http_fut =
|
let http_fut =
|
||||||
warp::serve(content_type_handler.clone()).bind(([127, 0, 0, 1], PORT));
|
warp::serve(content_type_handler.clone()).bind(([127, 0, 0, 1], PORT));
|
||||||
|
|
Loading…
Add table
Reference in a new issue