mirror of https://github.com/rwf2/Rocket.git
Return `HeaderMap` from Response::headers(). Remove Response::header_values().
This is a breaking change. A call to `Response::headers()` can be replaced with `Response::headers().iter()`. A call to `Response::header_values()` can be replaced with `Response::headers().get()`.
This commit is contained in:
parent
2e54a1f74d
commit
0d674c57fd
|
@ -12,8 +12,8 @@ fn test_submit() {
|
||||||
.header(ContentType::Form)
|
.header(ContentType::Form)
|
||||||
.body("message=Hello from Rocket!");
|
.body("message=Hello from Rocket!");
|
||||||
let response = request.dispatch_with(&rocket);
|
let response = request.dispatch_with(&rocket);
|
||||||
let cookie_headers: Vec<_> = response.header_values("Set-Cookie").collect();
|
let cookie_headers: Vec<_> = response.headers().get("Set-Cookie").collect();
|
||||||
let location_headers: Vec<_> = response.header_values("Location").collect();
|
let location_headers: Vec<_> = response.headers().get("Location").collect();
|
||||||
|
|
||||||
assert_eq!(response.status(), Status::SeeOther);
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
assert_eq!(cookie_headers, vec!["message=Hello%20from%20Rocket!".to_string()]);
|
assert_eq!(cookie_headers, vec!["message=Hello%20from%20Rocket!".to_string()]);
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn test_root() {
|
||||||
assert_eq!(response.status(), Status::SeeOther);
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
assert!(response.body().is_none());
|
assert!(response.body().is_none());
|
||||||
|
|
||||||
let location_headers: Vec<_> = response.header_values("Location").collect();
|
let location_headers: Vec<_> = response.headers().get("Location").collect();
|
||||||
assert_eq!(location_headers, vec!["/hello/Unknown"]);
|
assert_eq!(location_headers, vec!["/hello/Unknown"]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn test_303(uri: &str, expected_location: &str) {
|
||||||
.mount("/", routes![super::root, super::user, super::login]);
|
.mount("/", routes![super::root, super::user, super::login]);
|
||||||
let mut request = MockRequest::new(Method::Get, uri);
|
let mut request = MockRequest::new(Method::Get, uri);
|
||||||
let response = request.dispatch_with(&rocket);
|
let response = request.dispatch_with(&rocket);
|
||||||
let location_headers: Vec<_> = response.header_values("Location").collect();
|
let location_headers: Vec<_> = response.headers().get("Location").collect();
|
||||||
|
|
||||||
assert_eq!(response.status(), Status::SeeOther);
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
assert_eq!(location_headers, vec![expected_location]);
|
assert_eq!(location_headers, vec![expected_location]);
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn test_root() {
|
||||||
run_test!("/", |mut response: Response| {
|
run_test!("/", |mut response: Response| {
|
||||||
assert!(response.body().is_none());
|
assert!(response.body().is_none());
|
||||||
assert_eq!(response.status(), Status::SeeOther);
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
for h in response.headers() {
|
for h in response.headers().iter() {
|
||||||
match h.name.as_str() {
|
match h.name.as_str() {
|
||||||
"Location" => assert_eq!(h.value, "/login"),
|
"Location" => assert_eq!(h.value, "/login"),
|
||||||
"Content-Length" => assert_eq!(h.value.parse::<i32>().unwrap(), 0),
|
"Content-Length" => assert_eq!(h.value.parse::<i32>().unwrap(), 0),
|
||||||
|
|
|
@ -192,7 +192,8 @@ impl<'r> Request<'r> {
|
||||||
self.remote = Some(address);
|
self.remote = Some(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `HeaderMap` of all of the headers in `self`.
|
/// Returns a [HeaderMap](/rocket/http/struct.HeaderMap.html) of all of the
|
||||||
|
/// headers in `self`.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
|
|
@ -177,7 +177,7 @@ pub trait Responder<'r> {
|
||||||
/// let body_string = response.body().and_then(|b| b.into_string());
|
/// let body_string = response.body().and_then(|b| b.into_string());
|
||||||
/// assert_eq!(body_string, Some("Hello".to_string()));
|
/// assert_eq!(body_string, Some("Hello".to_string()));
|
||||||
///
|
///
|
||||||
/// let content_type: Vec<_> = response.header_values("Content-Type").collect();
|
/// let content_type: Vec<_> = response.headers().get("Content-Type").collect();
|
||||||
/// assert_eq!(content_type.len(), 1);
|
/// assert_eq!(content_type.len(), 1);
|
||||||
/// assert_eq!(content_type[0], ContentType::Plain.to_string());
|
/// assert_eq!(content_type[0], ContentType::Plain.to_string());
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -243,7 +243,7 @@ impl<'r> ResponseBuilder<'r> {
|
||||||
/// .header(ContentType::HTML)
|
/// .header(ContentType::HTML)
|
||||||
/// .finalize();
|
/// .finalize();
|
||||||
///
|
///
|
||||||
/// assert_eq!(response.header_values("Content-Type").count(), 1);
|
/// assert_eq!(response.headers().get("Content-Type").count(), 1);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn header<'h: 'r, H>(&mut self, header: H) -> &mut ResponseBuilder<'r>
|
pub fn header<'h: 'r, H>(&mut self, header: H) -> &mut ResponseBuilder<'r>
|
||||||
|
@ -274,7 +274,7 @@ impl<'r> ResponseBuilder<'r> {
|
||||||
/// .header_adjoin(Accept::text())
|
/// .header_adjoin(Accept::text())
|
||||||
/// .finalize();
|
/// .finalize();
|
||||||
///
|
///
|
||||||
/// assert_eq!(response.header_values("Accept").count(), 2);
|
/// assert_eq!(response.headers().get("Accept").count(), 2);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn header_adjoin<'h: 'r, H>(&mut self, header: H) -> &mut ResponseBuilder<'r>
|
pub fn header_adjoin<'h: 'r, H>(&mut self, header: H) -> &mut ResponseBuilder<'r>
|
||||||
|
@ -299,7 +299,7 @@ impl<'r> ResponseBuilder<'r> {
|
||||||
/// .raw_header("X-Custom", "second")
|
/// .raw_header("X-Custom", "second")
|
||||||
/// .finalize();
|
/// .finalize();
|
||||||
///
|
///
|
||||||
/// assert_eq!(response.header_values("X-Custom").count(), 1);
|
/// assert_eq!(response.headers().get("X-Custom").count(), 1);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn raw_header<'a: 'r, 'b: 'r, N, V>(&mut self, name: N, value: V)
|
pub fn raw_header<'a: 'r, 'b: 'r, N, V>(&mut self, name: N, value: V)
|
||||||
|
@ -326,7 +326,7 @@ impl<'r> ResponseBuilder<'r> {
|
||||||
/// .raw_header_adjoin("X-Custom", "second")
|
/// .raw_header_adjoin("X-Custom", "second")
|
||||||
/// .finalize();
|
/// .finalize();
|
||||||
///
|
///
|
||||||
/// assert_eq!(response.header_values("X-Custom").count(), 2);
|
/// assert_eq!(response.headers().get("X-Custom").count(), 2);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn raw_header_adjoin<'a: 'r, 'b: 'r, N, V>(&mut self, name: N, value: V)
|
pub fn raw_header_adjoin<'a: 'r, 'b: 'r, N, V>(&mut self, name: N, value: V)
|
||||||
|
@ -444,12 +444,12 @@ impl<'r> ResponseBuilder<'r> {
|
||||||
/// assert_eq!(response.status(), Status::NotFound);
|
/// assert_eq!(response.status(), Status::NotFound);
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let ctype: Vec<_> = response.header_values("Content-Type").collect();
|
/// let ctype: Vec<_> = response.headers().get("Content-Type").collect();
|
||||||
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
||||||
/// # }
|
/// # }
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let custom_values: Vec<_> = response.header_values("X-Custom").collect();
|
/// let custom_values: Vec<_> = response.headers().get("X-Custom").collect();
|
||||||
/// assert_eq!(custom_values, vec!["value 1"]);
|
/// assert_eq!(custom_values, vec!["value 1"]);
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -488,12 +488,12 @@ impl<'r> ResponseBuilder<'r> {
|
||||||
/// assert_eq!(response.status(), Status::ImATeapot);
|
/// assert_eq!(response.status(), Status::ImATeapot);
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let ctype: Vec<_> = response.header_values("Content-Type").collect();
|
/// let ctype: Vec<_> = response.headers().get("Content-Type").collect();
|
||||||
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
||||||
/// # }
|
/// # }
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let custom_values: Vec<_> = response.header_values("X-Custom").collect();
|
/// let custom_values: Vec<_> = response.headers().get("X-Custom").collect();
|
||||||
/// assert_eq!(custom_values, vec!["value 2", "value 3", "value 1"]);
|
/// assert_eq!(custom_values, vec!["value 2", "value 3", "value 1"]);
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -562,7 +562,7 @@ impl<'r> Response<'r> {
|
||||||
/// let mut response = Response::new();
|
/// let mut response = Response::new();
|
||||||
///
|
///
|
||||||
/// assert_eq!(response.status(), Status::Ok);
|
/// assert_eq!(response.status(), Status::Ok);
|
||||||
/// assert_eq!(response.headers().count(), 0);
|
/// assert_eq!(response.headers().len(), 0);
|
||||||
/// assert!(response.body().is_none());
|
/// assert!(response.body().is_none());
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -660,11 +660,8 @@ impl<'r> Response<'r> {
|
||||||
self.status = Some(Status::new(code, reason));
|
self.status = Some(Status::new(code, reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all of the headers stored in `self`. Multiple
|
/// Returns a [HeaderMap](/rocket/http/struct.HeaderMap.html) of all of the
|
||||||
/// headers with the same name may be returned, but all of the headers with
|
/// headers in `self`.
|
||||||
/// the same name will be appear in a group in the iterator. The values in
|
|
||||||
/// this group will be emitted in the order they were added to `self`. Aside
|
|
||||||
/// from this grouping, there are no other ordering guarantees.
|
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -676,34 +673,14 @@ impl<'r> Response<'r> {
|
||||||
/// response.adjoin_raw_header("X-Custom", "1");
|
/// response.adjoin_raw_header("X-Custom", "1");
|
||||||
/// response.adjoin_raw_header("X-Custom", "2");
|
/// response.adjoin_raw_header("X-Custom", "2");
|
||||||
///
|
///
|
||||||
/// let mut headers = response.headers();
|
/// let mut custom_headers = response.headers().iter();
|
||||||
/// assert_eq!(headers.next(), Some(Header::new("X-Custom", "1")));
|
/// assert_eq!(custom_headers.next(), Some(Header::new("X-Custom", "1")));
|
||||||
/// assert_eq!(headers.next(), Some(Header::new("X-Custom", "2")));
|
/// assert_eq!(custom_headers.next(), Some(Header::new("X-Custom", "2")));
|
||||||
/// assert_eq!(headers.next(), None);
|
/// assert_eq!(custom_headers.next(), None);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn headers<'a>(&'a self) -> impl Iterator<Item=Header<'a>> {
|
pub fn headers(&self) -> &HeaderMap<'r> {
|
||||||
self.headers.iter()
|
&self.headers
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns an iterator over all of the values stored in `self` for the
|
|
||||||
/// header with name `name`. The values are returned in FIFO order.
|
|
||||||
///
|
|
||||||
/// # Example
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// use rocket::Response;
|
|
||||||
///
|
|
||||||
/// let mut response = Response::new();
|
|
||||||
/// response.adjoin_raw_header("X-Custom", "1");
|
|
||||||
/// response.adjoin_raw_header("X-Custom", "2");
|
|
||||||
///
|
|
||||||
/// let values: Vec<_> = response.header_values("X-Custom").collect();
|
|
||||||
/// assert_eq!(values, vec!["1", "2"]);
|
|
||||||
/// ```
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn header_values<'h>(&'h self, name: &str) -> impl Iterator<Item=&'h str> {
|
|
||||||
self.headers.get(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the header `header` in `self`. Any existing headers with the name
|
/// Sets the header `header` in `self`. Any existing headers with the name
|
||||||
|
@ -721,12 +698,12 @@ impl<'r> Response<'r> {
|
||||||
/// let mut response = Response::new();
|
/// let mut response = Response::new();
|
||||||
///
|
///
|
||||||
/// response.set_header(ContentType::HTML);
|
/// response.set_header(ContentType::HTML);
|
||||||
/// assert_eq!(response.headers().next(), Some(ContentType::HTML.into()));
|
/// assert_eq!(response.headers().iter().next(), Some(ContentType::HTML.into()));
|
||||||
/// assert_eq!(response.headers().count(), 1);
|
/// assert_eq!(response.headers().len(), 1);
|
||||||
///
|
///
|
||||||
/// response.set_header(ContentType::JSON);
|
/// response.set_header(ContentType::JSON);
|
||||||
/// assert_eq!(response.headers().next(), Some(ContentType::JSON.into()));
|
/// assert_eq!(response.headers().iter().next(), Some(ContentType::JSON.into()));
|
||||||
/// assert_eq!(response.headers().count(), 1);
|
/// assert_eq!(response.headers().len(), 1);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn set_header<'h: 'r, H: Into<Header<'h>>>(&mut self, header: H) -> bool {
|
pub fn set_header<'h: 'r, H: Into<Header<'h>>>(&mut self, header: H) -> bool {
|
||||||
|
@ -747,12 +724,12 @@ impl<'r> Response<'r> {
|
||||||
/// let mut response = Response::new();
|
/// let mut response = Response::new();
|
||||||
///
|
///
|
||||||
/// response.set_raw_header("X-Custom", "1");
|
/// response.set_raw_header("X-Custom", "1");
|
||||||
/// assert_eq!(response.headers().next(), Some(Header::new("X-Custom", "1")));
|
/// assert_eq!(response.headers().get_one("X-Custom"), Some("1"));
|
||||||
/// assert_eq!(response.headers().count(), 1);
|
/// assert_eq!(response.headers().len(), 1);
|
||||||
///
|
///
|
||||||
/// response.set_raw_header("X-Custom", "2");
|
/// response.set_raw_header("X-Custom", "2");
|
||||||
/// assert_eq!(response.headers().next(), Some(Header::new("X-Custom", "2")));
|
/// assert_eq!(response.headers().get_one("X-Custom"), Some("2"));
|
||||||
/// assert_eq!(response.headers().count(), 1);
|
/// assert_eq!(response.headers().len(), 1);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn set_raw_header<'a: 'r, 'b: 'r, N, V>(&mut self, name: N, value: V) -> bool
|
pub fn set_raw_header<'a: 'r, 'b: 'r, N, V>(&mut self, name: N, value: V) -> bool
|
||||||
|
@ -778,7 +755,7 @@ impl<'r> Response<'r> {
|
||||||
/// response.adjoin_header(Accept::json());
|
/// response.adjoin_header(Accept::json());
|
||||||
/// response.adjoin_header(Accept::text());
|
/// response.adjoin_header(Accept::text());
|
||||||
///
|
///
|
||||||
/// let mut accept_headers = response.headers();
|
/// let mut accept_headers = response.headers().iter();
|
||||||
/// assert_eq!(accept_headers.next(), Some(Accept::json().into()));
|
/// assert_eq!(accept_headers.next(), Some(Accept::json().into()));
|
||||||
/// assert_eq!(accept_headers.next(), Some(Accept::text().into()));
|
/// assert_eq!(accept_headers.next(), Some(Accept::text().into()));
|
||||||
/// assert_eq!(accept_headers.next(), None);
|
/// assert_eq!(accept_headers.next(), None);
|
||||||
|
@ -805,7 +782,7 @@ impl<'r> Response<'r> {
|
||||||
/// response.adjoin_raw_header("X-Custom", "one");
|
/// response.adjoin_raw_header("X-Custom", "one");
|
||||||
/// response.adjoin_raw_header("X-Custom", "two");
|
/// response.adjoin_raw_header("X-Custom", "two");
|
||||||
///
|
///
|
||||||
/// let mut custom_headers = response.headers();
|
/// let mut custom_headers = response.headers().iter();
|
||||||
/// assert_eq!(custom_headers.next(), Some(Header::new("X-Custom", "one")));
|
/// assert_eq!(custom_headers.next(), Some(Header::new("X-Custom", "one")));
|
||||||
/// assert_eq!(custom_headers.next(), Some(Header::new("X-Custom", "two")));
|
/// assert_eq!(custom_headers.next(), Some(Header::new("X-Custom", "two")));
|
||||||
/// assert_eq!(custom_headers.next(), None);
|
/// assert_eq!(custom_headers.next(), None);
|
||||||
|
@ -829,10 +806,10 @@ impl<'r> Response<'r> {
|
||||||
/// response.adjoin_raw_header("X-Custom", "one");
|
/// response.adjoin_raw_header("X-Custom", "one");
|
||||||
/// response.adjoin_raw_header("X-Custom", "two");
|
/// response.adjoin_raw_header("X-Custom", "two");
|
||||||
/// response.adjoin_raw_header("X-Other", "hi");
|
/// response.adjoin_raw_header("X-Other", "hi");
|
||||||
/// assert_eq!(response.headers().count(), 3);
|
/// assert_eq!(response.headers().len(), 3);
|
||||||
///
|
///
|
||||||
/// response.remove_header("X-Custom");
|
/// response.remove_header("X-Custom");
|
||||||
/// assert_eq!(response.headers().count(), 1);
|
/// assert_eq!(response.headers().len(), 1);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn remove_header(&mut self, name: &str) {
|
pub fn remove_header(&mut self, name: &str) {
|
||||||
|
@ -1034,12 +1011,12 @@ impl<'r> Response<'r> {
|
||||||
/// assert_eq!(response.status(), Status::NotFound);
|
/// assert_eq!(response.status(), Status::NotFound);
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let ctype: Vec<_> = response.header_values("Content-Type").collect();
|
/// let ctype: Vec<_> = response.headers().get("Content-Type").collect();
|
||||||
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
||||||
/// # }
|
/// # }
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let custom_values: Vec<_> = response.header_values("X-Custom").collect();
|
/// let custom_values: Vec<_> = response.headers().get("X-Custom").collect();
|
||||||
/// assert_eq!(custom_values, vec!["value 1"]);
|
/// assert_eq!(custom_values, vec!["value 1"]);
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1083,12 +1060,12 @@ impl<'r> Response<'r> {
|
||||||
/// assert_eq!(response.status(), Status::ImATeapot);
|
/// assert_eq!(response.status(), Status::ImATeapot);
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let ctype: Vec<_> = response.header_values("Content-Type").collect();
|
/// let ctype: Vec<_> = response.headers().get("Content-Type").collect();
|
||||||
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
/// assert_eq!(ctype, vec![ContentType::HTML.to_string()]);
|
||||||
/// # }
|
/// # }
|
||||||
///
|
///
|
||||||
/// # {
|
/// # {
|
||||||
/// let custom_values: Vec<_> = response.header_values("X-Custom").collect();
|
/// let custom_values: Vec<_> = response.headers().get("X-Custom").collect();
|
||||||
/// assert_eq!(custom_values, vec!["value 2", "value 3", "value 1"]);
|
/// assert_eq!(custom_values, vec!["value 2", "value 3", "value 1"]);
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1111,7 +1088,7 @@ impl<'r> fmt::Debug for Response<'r> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
writeln!(f, "{}", self.status())?;
|
writeln!(f, "{}", self.status())?;
|
||||||
|
|
||||||
for header in self.headers() {
|
for header in self.headers().iter() {
|
||||||
writeln!(f, "{}", header)?;
|
writeln!(f, "{}", header)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ impl Rocket {
|
||||||
{
|
{
|
||||||
*hyp_res.status_mut() = hyper::StatusCode::from_u16(response.status().code);
|
*hyp_res.status_mut() = hyper::StatusCode::from_u16(response.status().code);
|
||||||
|
|
||||||
for header in response.headers() {
|
for header in response.headers().iter() {
|
||||||
// FIXME: Using hyper here requires two allocations.
|
// FIXME: Using hyper here requires two allocations.
|
||||||
let name = header.name.into_string();
|
let name = header.name.into_string();
|
||||||
let value = Vec::from(header.value.as_bytes());
|
let value = Vec::from(header.value.as_bytes());
|
||||||
|
|
|
@ -54,7 +54,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let content_type: Vec<_> = response.header_values("Content-Type").collect();
|
let content_type: Vec<_> = response.headers().get("Content-Type").collect();
|
||||||
assert_eq!(content_type, vec![ContentType::Plain.to_string()]);
|
assert_eq!(content_type, vec![ContentType::Plain.to_string()]);
|
||||||
|
|
||||||
let mut req = MockRequest::new(Head, "/empty");
|
let mut req = MockRequest::new(Head, "/empty");
|
||||||
|
@ -70,7 +70,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(response.status(), Status::Ok);
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
|
||||||
let content_type: Vec<_> = response.header_values("Content-Type").collect();
|
let content_type: Vec<_> = response.headers().get("Content-Type").collect();
|
||||||
assert_eq!(content_type, vec![ContentType::JSON.to_string()]);
|
assert_eq!(content_type, vec![ContentType::JSON.to_string()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ mod tests {
|
||||||
let response = req.dispatch_with(&rocket);
|
let response = req.dispatch_with(&rocket);
|
||||||
println!("Response:\n{:?}", response);
|
println!("Response:\n{:?}", response);
|
||||||
|
|
||||||
let location: Vec<_> = response.header_values("location").collect();
|
let location: Vec<_> = response.headers().get("location").collect();
|
||||||
assert_eq!(response.status(), Status::SeeOther);
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
assert_eq!(location, vec!["/"]);
|
assert_eq!(location, vec!["/"]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue