mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
This reverts commit f5c84920c2
.
This commit is contained in:
parent
aa657d6493
commit
d4a24c870e
3 changed files with 48 additions and 207 deletions
|
@ -76,7 +76,10 @@ fn resolve_url_from_location(base_url: &Url, location: &str) -> Url {
|
|||
}
|
||||
}
|
||||
|
||||
pub type HeadersMap = HashMap<String, Vec<String>>;
|
||||
// TODO(ry) HTTP headers are not unique key, value pairs. There may be more than
|
||||
// one header line with the same key. This should be changed to something like
|
||||
// Vec<(String, String)>
|
||||
pub type HeadersMap = HashMap<String, String>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum FetchOnceResult {
|
||||
|
@ -109,7 +112,7 @@ pub async fn fetch_once(
|
|||
return Ok(FetchOnceResult::NotModified);
|
||||
}
|
||||
|
||||
let mut headers_: HashMap<String, Vec<String>> = HashMap::new();
|
||||
let mut headers_: HashMap<String, String> = HashMap::new();
|
||||
let headers = response.headers();
|
||||
|
||||
if let Some(warning) = headers.get("X-Deno-Warning") {
|
||||
|
@ -128,10 +131,7 @@ pub async fn fetch_once(
|
|||
.map(|e| e.to_str().unwrap().to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(",");
|
||||
headers_
|
||||
.entry(key_str)
|
||||
.or_insert_with(Vec::new)
|
||||
.push(values_str);
|
||||
headers_.insert(key_str, values_str);
|
||||
}
|
||||
|
||||
if response.status().is_redirection() {
|
||||
|
@ -248,15 +248,7 @@ mod tests {
|
|||
let result = fetch_once(client, &url, None).await;
|
||||
if let Ok(FetchOnceResult::Code(body, headers)) = result {
|
||||
assert!(!body.is_empty());
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
"application/json"
|
||||
);
|
||||
assert_eq!(headers.get("content-type").unwrap(), "application/json");
|
||||
assert_eq!(headers.get("etag"), None);
|
||||
assert_eq!(headers.get("x-typescript-types"), None);
|
||||
} else {
|
||||
|
@ -277,12 +269,7 @@ mod tests {
|
|||
if let Ok(FetchOnceResult::Code(body, headers)) = result {
|
||||
assert_eq!(String::from_utf8(body).unwrap(), "console.log('gzip')");
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
headers.get("content-type").unwrap(),
|
||||
"application/javascript"
|
||||
);
|
||||
assert_eq!(headers.get("etag"), None);
|
||||
|
@ -302,18 +289,10 @@ mod tests {
|
|||
assert!(!body.is_empty());
|
||||
assert_eq!(String::from_utf8(body).unwrap(), "console.log('etag')");
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
headers.get("content-type").unwrap(),
|
||||
"application/typescript"
|
||||
);
|
||||
assert_eq!(
|
||||
headers.get("etag").unwrap().first().unwrap().as_str(),
|
||||
"33a64df551425fcc55e"
|
||||
);
|
||||
assert_eq!(headers.get("etag").unwrap(), "33a64df551425fcc55e");
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
|
@ -337,12 +316,7 @@ mod tests {
|
|||
assert!(!body.is_empty());
|
||||
assert_eq!(String::from_utf8(body).unwrap(), "console.log('brotli');");
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
headers.get("content-type").unwrap(),
|
||||
"application/javascript"
|
||||
);
|
||||
assert_eq!(headers.get("etag"), None);
|
||||
|
@ -425,15 +399,7 @@ mod tests {
|
|||
let result = fetch_once(client, &url, None).await;
|
||||
if let Ok(FetchOnceResult::Code(body, headers)) = result {
|
||||
assert!(!body.is_empty());
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
"application/json"
|
||||
);
|
||||
assert_eq!(headers.get("content-type").unwrap(), "application/json");
|
||||
assert_eq!(headers.get("etag"), None);
|
||||
assert_eq!(headers.get("x-typescript-types"), None);
|
||||
} else {
|
||||
|
@ -460,12 +426,7 @@ mod tests {
|
|||
if let Ok(FetchOnceResult::Code(body, headers)) = result {
|
||||
assert_eq!(String::from_utf8(body).unwrap(), "console.log('gzip')");
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
headers.get("content-type").unwrap(),
|
||||
"application/javascript"
|
||||
);
|
||||
assert_eq!(headers.get("etag"), None);
|
||||
|
@ -491,18 +452,10 @@ mod tests {
|
|||
assert!(!body.is_empty());
|
||||
assert_eq!(String::from_utf8(body).unwrap(), "console.log('etag')");
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
headers.get("content-type").unwrap(),
|
||||
"application/typescript"
|
||||
);
|
||||
assert_eq!(
|
||||
headers.get("etag").unwrap().first().unwrap().as_str(),
|
||||
"33a64df551425fcc55e"
|
||||
);
|
||||
assert_eq!(headers.get("etag").unwrap(), "33a64df551425fcc55e");
|
||||
assert_eq!(headers.get("x-typescript-types"), None);
|
||||
} else {
|
||||
panic!();
|
||||
|
@ -533,12 +486,7 @@ mod tests {
|
|||
assert!(!body.is_empty());
|
||||
assert_eq!(String::from_utf8(body).unwrap(), "console.log('brotli');");
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("content-type")
|
||||
.unwrap()
|
||||
.first()
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
headers.get("content-type").unwrap(),
|
||||
"application/javascript"
|
||||
);
|
||||
assert_eq!(headers.get("etag"), None);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue