request: test adding duplicate headers to the request (#519)

This commit is contained in:
Ben Boeckel
2019-05-03 14:48:31 -04:00
committed by Sean McArthur
parent bf5a268079
commit 1bdc3fa3c8
2 changed files with 46 additions and 1 deletions

View File

@@ -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();