1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00
actix-web/tests/test_httpresponse.rs

42 lines
1.2 KiB
Rust
Raw Normal View History

2017-10-16 18:43:10 +02:00
extern crate actix_web;
extern crate http;
extern crate time;
use actix_web::*;
2017-12-01 04:01:25 +01:00
use std::str::FromStr;
2017-10-16 18:43:10 +02:00
use time::Duration;
2017-12-01 04:01:25 +01:00
use http::{header, Method, Version, HeaderMap, Uri};
2017-10-16 18:43:10 +02:00
#[test]
fn test_response_cookies() {
let mut headers = HeaderMap::new();
headers.insert(header::COOKIE,
header::HeaderValue::from_static("cookie1=value1; cookie2=value2"));
2017-12-08 03:00:20 +01:00
let req = HttpRequest::new(
2017-12-13 17:00:25 +01:00
Method::GET, Uri::from_str("/").unwrap(), Version::HTTP_11, headers, None);
2017-12-08 03:00:20 +01:00
let cookies = req.cookies().unwrap();
2017-10-16 18:43:10 +02:00
let resp = httpcodes::HTTPOk
2017-11-27 07:31:29 +01:00
.build()
2017-12-08 01:40:29 +01:00
.cookie(headers::Cookie::build("name", "value")
2017-10-16 18:43:10 +02:00
.domain("www.rust-lang.org")
.path("/test")
.http_only(true)
.max_age(Duration::days(1))
.finish())
.del_cookie(&cookies[0])
.body(Body::Empty);
assert!(resp.is_ok());
let resp = resp.unwrap();
let mut val: Vec<_> = resp.headers().get_all("Set-Cookie")
.iter().map(|v| v.to_str().unwrap().to_owned()).collect();
val.sort();
assert!(val[0].starts_with("cookie1=; Max-Age=0;"));
assert_eq!(
val[1],"name=value; HttpOnly; Path=/test; Domain=www.rust-lang.org; Max-Age=86400");
}