From d4a24c870e87b55dab425bc2c320aa88a6224030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 16 Sep 2020 13:34:16 +0200 Subject: Revert "fix(cli/http_utils): accept a single key-multiple values headers (#7375)" (#7515) This reverts commit f5c84920c225579af9c249bdac4a59a046ef8683. --- cli/http_util.rs | 84 +++++++++++--------------------------------------------- 1 file changed, 16 insertions(+), 68 deletions(-) (limited to 'cli/http_util.rs') 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>; +// 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; #[derive(Debug, PartialEq)] pub enum FetchOnceResult { @@ -109,7 +112,7 @@ pub async fn fetch_once( return Ok(FetchOnceResult::NotModified); } - let mut headers_: HashMap> = HashMap::new(); + let mut headers_: HashMap = 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::>() .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); -- cgit v1.2.3