diff --git a/src/async_impl/request.rs b/src/async_impl/request.rs index 431765f..f6460f5 100644 --- a/src/async_impl/request.rs +++ b/src/async_impl/request.rs @@ -642,6 +642,27 @@ mod tests { assert_eq!(r.headers, headers); } + #[test] + fn add_headers_multi() { + let client = Client::new().unwrap(); + let some_url = "https://google.com/"; + let mut r = client.post(some_url).unwrap(); + + let header = Host { + hostname: "google.com".to_string(), + port: None, + }; + + let mut headers = Headers::new(); + headers.set(header); + + // Add a copy of the headers to the request builder + let r = r.headers(headers.clone()).build(); + + // then make sure they were added correctly + assert_eq!(r.headers, headers); + } + #[test] fn add_body() { let client = Client::new().unwrap(); diff --git a/src/request.rs b/src/request.rs index 1602556..a158408 100644 --- a/src/request.rs +++ b/src/request.rs @@ -580,7 +580,7 @@ fn fmt_request_fields<'a, 'b>(f: &'a mut fmt::DebugStruct<'a, 'b>, req: &Request #[cfg(test)] mod tests { use {body, Client, Method}; - use header::{HOST, HeaderMap, HeaderValue, CONTENT_TYPE}; + use header::{ACCEPT, HOST, HeaderMap, HeaderValue, CONTENT_TYPE}; use std::collections::{BTreeMap, HashMap}; use serde_json; use serde_urlencoded; @@ -678,6 +678,30 @@ mod tests { assert_eq!(r.headers(), &headers); } + #[test] + fn add_headers_multi() { + let client = Client::new(); + let some_url = "https://google.com/"; + let r = client.post(some_url); + + let header_json = HeaderValue::from_static("application/json"); + let header_xml = HeaderValue::from_static("application/xml"); + + let mut headers = HeaderMap::new(); + headers.append(ACCEPT, header_json); + headers.append(ACCEPT, header_xml); + + // Add a copy of the headers to the request builder + let r = r.headers(headers.clone()).build().unwrap(); + + // then make sure they were added correctly + assert_eq!(r.headers(), &headers); + let mut all_values = r.headers().get_all(ACCEPT).iter(); + assert_eq!(all_values.next().unwrap(), &"application/json"); + assert_eq!(all_values.next().unwrap(), &"application/xml"); + assert_eq!(all_values.next(), None); + } + #[test] fn add_body() { let client = Client::new();