diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-09-16 13:34:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-16 13:34:16 +0200 |
commit | d4a24c870e87b55dab425bc2c320aa88a6224030 (patch) | |
tree | e4ab9c88251166c711a03ad305f4d2b48f8369b1 /cli/http_util.rs | |
parent | aa657d6493cb0f36a5e2aa29e6352c9a9991ad2b (diff) |
Revert "fix(cli/http_utils): accept a single key-multiple values headers (#7375)" (#7515)
This reverts commit f5c84920c225579af9c249bdac4a59a046ef8683.
Diffstat (limited to 'cli/http_util.rs')
-rw-r--r-- | cli/http_util.rs | 84 |
1 files changed, 16 insertions, 68 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs index ebd84972d..015bfaa46 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -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); |