mirror of https://github.com/fafhrd91/actix-web
fix doctests
This commit is contained in:
parent
698737950a
commit
e68f589ccd
|
@ -101,7 +101,7 @@ mod tests {
|
||||||
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
|
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(header::IF_MODIFIED_SINCE, since)
|
.insert_header((header::IF_MODIFIED_SINCE, since))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
let resp = file.respond_to(&req).await.unwrap();
|
let resp = file.respond_to(&req).await.unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::NOT_MODIFIED);
|
assert_eq!(resp.status(), StatusCode::NOT_MODIFIED);
|
||||||
|
@ -126,8 +126,8 @@ mod tests {
|
||||||
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
|
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(header::IF_NONE_MATCH, "miss_etag")
|
.insert_header((header::IF_NONE_MATCH, "miss_etag"))
|
||||||
.header(header::IF_MODIFIED_SINCE, since)
|
.insert_header((header::IF_MODIFIED_SINCE, since))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
let resp = file.respond_to(&req).await.unwrap();
|
let resp = file.respond_to(&req).await.unwrap();
|
||||||
assert_ne!(resp.status(), StatusCode::NOT_MODIFIED);
|
assert_ne!(resp.status(), StatusCode::NOT_MODIFIED);
|
||||||
|
@ -398,7 +398,7 @@ mod tests {
|
||||||
// Valid range header
|
// Valid range header
|
||||||
let request = TestRequest::get()
|
let request = TestRequest::get()
|
||||||
.uri("/t%65st/Cargo.toml")
|
.uri("/t%65st/Cargo.toml")
|
||||||
.header(header::RANGE, "bytes=10-20")
|
.insert_header((header::RANGE, "bytes=10-20"))
|
||||||
.to_request();
|
.to_request();
|
||||||
let response = test::call_service(&mut srv, request).await;
|
let response = test::call_service(&mut srv, request).await;
|
||||||
assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);
|
assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);
|
||||||
|
@ -406,7 +406,7 @@ mod tests {
|
||||||
// Invalid range header
|
// Invalid range header
|
||||||
let request = TestRequest::get()
|
let request = TestRequest::get()
|
||||||
.uri("/t%65st/Cargo.toml")
|
.uri("/t%65st/Cargo.toml")
|
||||||
.header(header::RANGE, "bytes=1-0")
|
.insert_header((header::RANGE, "bytes=1-0"))
|
||||||
.to_request();
|
.to_request();
|
||||||
let response = test::call_service(&mut srv, request).await;
|
let response = test::call_service(&mut srv, request).await;
|
||||||
|
|
||||||
|
@ -420,7 +420,7 @@ mod tests {
|
||||||
// Valid range header
|
// Valid range header
|
||||||
let response = srv
|
let response = srv
|
||||||
.get("/tests/test.binary")
|
.get("/tests/test.binary")
|
||||||
.header(header::RANGE, "bytes=10-20")
|
.insert_header((header::RANGE, "bytes=10-20"))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -430,7 +430,7 @@ mod tests {
|
||||||
// Invalid range header
|
// Invalid range header
|
||||||
let response = srv
|
let response = srv
|
||||||
.get("/tests/test.binary")
|
.get("/tests/test.binary")
|
||||||
.header(header::RANGE, "bytes=10-5")
|
.insert_header((header::RANGE, "bytes=10-5"))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -445,7 +445,7 @@ mod tests {
|
||||||
// Valid range header
|
// Valid range header
|
||||||
let response = srv
|
let response = srv
|
||||||
.get("/tests/test.binary")
|
.get("/tests/test.binary")
|
||||||
.header(header::RANGE, "bytes=10-20")
|
.insert_header((header::RANGE, "bytes=10-20"))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -455,7 +455,7 @@ mod tests {
|
||||||
// Valid range header, starting from 0
|
// Valid range header, starting from 0
|
||||||
let response = srv
|
let response = srv
|
||||||
.get("/tests/test.binary")
|
.get("/tests/test.binary")
|
||||||
.header(header::RANGE, "bytes=0-20")
|
.insert_header((header::RANGE, "bytes=0-20"))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -560,7 +560,7 @@ mod tests {
|
||||||
|
|
||||||
let request = TestRequest::get()
|
let request = TestRequest::get()
|
||||||
.uri("/")
|
.uri("/")
|
||||||
.header(header::ACCEPT_ENCODING, "gzip")
|
.insert_header((header::ACCEPT_ENCODING, "gzip"))
|
||||||
.to_request();
|
.to_request();
|
||||||
let res = test::call_service(&mut srv, request).await;
|
let res = test::call_service(&mut srv, request).await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::OK);
|
||||||
|
@ -580,7 +580,7 @@ mod tests {
|
||||||
|
|
||||||
let request = TestRequest::get()
|
let request = TestRequest::get()
|
||||||
.uri("/")
|
.uri("/")
|
||||||
.header(header::ACCEPT_ENCODING, "gzip")
|
.insert_header((header::ACCEPT_ENCODING, "gzip"))
|
||||||
.to_request();
|
.to_request();
|
||||||
let res = test::call_service(&mut srv, request).await;
|
let res = test::call_service(&mut srv, request).await;
|
||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::OK);
|
||||||
|
|
|
@ -282,16 +282,16 @@ impl NamedFile {
|
||||||
|
|
||||||
if self.flags.contains(Flags::PREFER_UTF8) {
|
if self.flags.contains(Flags::PREFER_UTF8) {
|
||||||
let ct = equiv_utf8_text(self.content_type.clone());
|
let ct = equiv_utf8_text(self.content_type.clone());
|
||||||
res.header(header::CONTENT_TYPE, ct.to_string());
|
res.insert_header((header::CONTENT_TYPE, ct.to_string()));
|
||||||
} else {
|
} else {
|
||||||
res.header(header::CONTENT_TYPE, self.content_type.to_string());
|
res.insert_header((header::CONTENT_TYPE, self.content_type.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.flags.contains(Flags::CONTENT_DISPOSITION) {
|
if self.flags.contains(Flags::CONTENT_DISPOSITION) {
|
||||||
res.header(
|
res.insert_header((
|
||||||
header::CONTENT_DISPOSITION,
|
header::CONTENT_DISPOSITION,
|
||||||
self.content_disposition.to_string(),
|
self.content_disposition.to_string(),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(current_encoding) = self.encoding {
|
if let Some(current_encoding) = self.encoding {
|
||||||
|
@ -361,16 +361,16 @@ impl NamedFile {
|
||||||
|
|
||||||
if self.flags.contains(Flags::PREFER_UTF8) {
|
if self.flags.contains(Flags::PREFER_UTF8) {
|
||||||
let ct = equiv_utf8_text(self.content_type.clone());
|
let ct = equiv_utf8_text(self.content_type.clone());
|
||||||
resp.header(header::CONTENT_TYPE, ct.to_string());
|
resp.insert_header((header::CONTENT_TYPE, ct.to_string()));
|
||||||
} else {
|
} else {
|
||||||
resp.header(header::CONTENT_TYPE, self.content_type.to_string());
|
resp.insert_header((header::CONTENT_TYPE, self.content_type.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.flags.contains(Flags::CONTENT_DISPOSITION) {
|
if self.flags.contains(Flags::CONTENT_DISPOSITION) {
|
||||||
resp.header(
|
resp.insert_header((
|
||||||
header::CONTENT_DISPOSITION,
|
header::CONTENT_DISPOSITION,
|
||||||
self.content_disposition.to_string(),
|
self.content_disposition.to_string(),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// default compressing
|
// default compressing
|
||||||
|
@ -379,14 +379,14 @@ impl NamedFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(lm) = last_modified {
|
if let Some(lm) = last_modified {
|
||||||
resp.header(header::LAST_MODIFIED, lm.to_string());
|
resp.insert_header((header::LAST_MODIFIED, lm.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(etag) = etag {
|
if let Some(etag) = etag {
|
||||||
resp.header(header::ETAG, etag.to_string());
|
resp.insert_header((header::ETAG, etag.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.header(header::ACCEPT_RANGES, "bytes");
|
resp.insert_header((header::ACCEPT_RANGES, "bytes"));
|
||||||
|
|
||||||
let mut length = self.md.len();
|
let mut length = self.md.len();
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
|
@ -399,7 +399,7 @@ impl NamedFile {
|
||||||
offset = ranges[0].start;
|
offset = ranges[0].start;
|
||||||
|
|
||||||
resp.encoding(ContentEncoding::Identity);
|
resp.encoding(ContentEncoding::Identity);
|
||||||
resp.header(
|
resp.insert_header((
|
||||||
header::CONTENT_RANGE,
|
header::CONTENT_RANGE,
|
||||||
format!(
|
format!(
|
||||||
"bytes {}-{}/{}",
|
"bytes {}-{}/{}",
|
||||||
|
@ -407,9 +407,12 @@ impl NamedFile {
|
||||||
offset + length - 1,
|
offset + length - 1,
|
||||||
self.md.len()
|
self.md.len()
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
} else {
|
} else {
|
||||||
resp.header(header::CONTENT_RANGE, format!("bytes */{}", length));
|
resp.insert_header((
|
||||||
|
header::CONTENT_RANGE,
|
||||||
|
format!("bytes */{}", length),
|
||||||
|
));
|
||||||
return resp.status(StatusCode::RANGE_NOT_SATISFIABLE).finish();
|
return resp.status(StatusCode::RANGE_NOT_SATISFIABLE).finish();
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
if !is_method_valid {
|
if !is_method_valid {
|
||||||
return Either::Left(ok(req.into_response(
|
return Either::Left(ok(req.into_response(
|
||||||
actix_web::HttpResponse::MethodNotAllowed()
|
actix_web::HttpResponse::MethodNotAllowed()
|
||||||
.header(header::CONTENT_TYPE, "text/plain")
|
.insert_header(header::ContentType(mime::TEXT_PLAIN_UTF_8))
|
||||||
.body("Request did not meet this resource's requirements."),
|
.body("Request did not meet this resource's requirements."),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
|
|
||||||
return Either::Left(ok(req.into_response(
|
return Either::Left(ok(req.into_response(
|
||||||
HttpResponse::Found()
|
HttpResponse::Found()
|
||||||
.header(header::LOCATION, redirect_to)
|
.insert_header((header::LOCATION, redirect_to))
|
||||||
.body("")
|
.body("")
|
||||||
.into_body(),
|
.into_body(),
|
||||||
)));
|
)));
|
||||||
|
|
|
@ -26,7 +26,10 @@ async fn main() -> io::Result<()> {
|
||||||
info!("request body: {:?}", body);
|
info!("request body: {:?}", body);
|
||||||
Ok::<_, Error>(
|
Ok::<_, Error>(
|
||||||
Response::Ok()
|
Response::Ok()
|
||||||
.header("x-head", HeaderValue::from_static("dummy value!"))
|
.insert_header((
|
||||||
|
"x-head",
|
||||||
|
HeaderValue::from_static("dummy value!"),
|
||||||
|
))
|
||||||
.body(body),
|
.body(body),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,7 +15,7 @@ async fn handle_request(mut req: Request) -> Result<Response, Error> {
|
||||||
|
|
||||||
info!("request body: {:?}", body);
|
info!("request body: {:?}", body);
|
||||||
Ok(Response::Ok()
|
Ok(Response::Ok()
|
||||||
.header("x-head", HeaderValue::from_static("dummy value!"))
|
.insert_header(("x-head", HeaderValue::from_static("dummy value!")))
|
||||||
.body(body))
|
.body(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@ async fn main() -> io::Result<()> {
|
||||||
.finish(|_req| {
|
.finish(|_req| {
|
||||||
info!("{:?}", _req);
|
info!("{:?}", _req);
|
||||||
let mut res = Response::Ok();
|
let mut res = Response::Ok();
|
||||||
res.header("x-head", HeaderValue::from_static("dummy value!"));
|
res.insert_header((
|
||||||
|
"x-head",
|
||||||
|
HeaderValue::from_static("dummy value!"),
|
||||||
|
));
|
||||||
future::ok::<_, ()>(res.body("Hello world!"))
|
future::ok::<_, ()>(res.body("Hello world!"))
|
||||||
})
|
})
|
||||||
.tcp()
|
.tcp()
|
||||||
|
|
|
@ -32,50 +32,36 @@ header! {
|
||||||
/// * `text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c`
|
/// * `text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c`
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
|
||||||
/// extern crate mime;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{Accept, qitem};
|
/// use actix_http::http::header::{Accept, qitem};
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
///
|
/// builder.insert_header(
|
||||||
/// builder.set(
|
|
||||||
/// Accept(vec![
|
/// Accept(vec![
|
||||||
/// qitem(mime::TEXT_HTML),
|
/// qitem(mime::TEXT_HTML),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
|
||||||
/// extern crate mime;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{Accept, qitem};
|
/// use actix_http::http::header::{Accept, qitem};
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
///
|
/// builder.insert_header(
|
||||||
/// builder.set(
|
|
||||||
/// Accept(vec![
|
/// Accept(vec![
|
||||||
/// qitem(mime::APPLICATION_JSON),
|
/// qitem(mime::APPLICATION_JSON),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
|
||||||
/// extern crate mime;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{Accept, QualityItem, q, qitem};
|
/// use actix_http::http::header::{Accept, QualityItem, q, qitem};
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
///
|
/// builder.insert_header(
|
||||||
/// builder.set(
|
|
||||||
/// Accept(vec![
|
/// Accept(vec![
|
||||||
/// qitem(mime::TEXT_HTML),
|
/// qitem(mime::TEXT_HTML),
|
||||||
/// qitem("application/xhtml+xml".parse().unwrap()),
|
/// qitem("application/xhtml+xml".parse().unwrap()),
|
||||||
|
@ -90,7 +76,6 @@ header! {
|
||||||
/// ),
|
/// ),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
(Accept, header::ACCEPT) => (QualityItem<Mime>)+
|
(Accept, header::ACCEPT) => (QualityItem<Mime>)+
|
||||||
|
|
||||||
|
@ -132,7 +117,7 @@ header! {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fuzzing1() {
|
fn test_fuzzing1() {
|
||||||
use crate::test::TestRequest;
|
use crate::test::TestRequest;
|
||||||
let req = TestRequest::default().insert_header(crate::header::ACCEPT, "chunk#;e").finish();
|
let req = TestRequest::default().insert_header((crate::header::ACCEPT, "chunk#;e")).finish();
|
||||||
let header = Accept::parse(&req);
|
let header = Accept::parse(&req);
|
||||||
assert!(header.is_ok());
|
assert!(header.is_ok());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,44 +21,37 @@ header! {
|
||||||
/// * `iso-8859-5, unicode-1-1;q=0.8`
|
/// * `iso-8859-5, unicode-1-1;q=0.8`
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{AcceptCharset, Charset, qitem};
|
/// use actix_http::http::header::{AcceptCharset, Charset, qitem};
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// AcceptCharset(vec![qitem(Charset::Us_Ascii)])
|
/// AcceptCharset(vec![qitem(Charset::Us_Ascii)])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
/// ```rust
|
///
|
||||||
/// # extern crate actix_http;
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{AcceptCharset, Charset, q, QualityItem};
|
/// use actix_http::http::header::{AcceptCharset, Charset, q, QualityItem};
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// AcceptCharset(vec![
|
/// AcceptCharset(vec![
|
||||||
/// QualityItem::new(Charset::Us_Ascii, q(900)),
|
/// QualityItem::new(Charset::Us_Ascii, q(900)),
|
||||||
/// QualityItem::new(Charset::Iso_8859_10, q(200)),
|
/// QualityItem::new(Charset::Iso_8859_10, q(200)),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
/// ```rust
|
///
|
||||||
/// # extern crate actix_http;
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{AcceptCharset, Charset, qitem};
|
/// use actix_http::http::header::{AcceptCharset, Charset, qitem};
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// AcceptCharset(vec![qitem(Charset::Ext("utf-8".to_owned()))])
|
/// AcceptCharset(vec![qitem(Charset::Ext("utf-8".to_owned()))])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+
|
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+
|
||||||
|
|
||||||
|
|
|
@ -22,41 +22,35 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
/// use language_tags::langtag;
|
||||||
/// # extern crate language_tags;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{AcceptLanguage, LanguageTag, qitem};
|
/// use actix_http::http::header::{AcceptLanguage, LanguageTag, qitem};
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// let mut langtag: LanguageTag = Default::default();
|
/// let mut langtag: LanguageTag = Default::default();
|
||||||
/// langtag.language = Some("en".to_owned());
|
/// langtag.language = Some("en".to_owned());
|
||||||
/// langtag.region = Some("US".to_owned());
|
/// langtag.region = Some("US".to_owned());
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// AcceptLanguage(vec![
|
/// AcceptLanguage(vec![
|
||||||
/// qitem(langtag),
|
/// qitem(langtag),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
/// use language_tags::langtag;
|
||||||
/// # #[macro_use] extern crate language_tags;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{AcceptLanguage, QualityItem, q, qitem};
|
/// use actix_http::http::header::{AcceptLanguage, QualityItem, q, qitem};
|
||||||
/// #
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// AcceptLanguage(vec![
|
/// AcceptLanguage(vec![
|
||||||
/// qitem(langtag!(da)),
|
/// qitem(langtag!(da)),
|
||||||
/// QualityItem::new(langtag!(en;;;GB), q(800)),
|
/// QualityItem::new(langtag!(en;;;GB), q(800)),
|
||||||
/// QualityItem::new(langtag!(en), q(700)),
|
/// QualityItem::new(langtag!(en), q(700)),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
(AcceptLanguage, ACCEPT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
(AcceptLanguage, ACCEPT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
||||||
|
|
||||||
|
|
|
@ -22,38 +22,28 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate http;
|
|
||||||
/// # extern crate actix_http;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::Allow;
|
/// use actix_http::http::{header::Allow, Method};
|
||||||
/// use http::Method;
|
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// Allow(vec![Method::GET])
|
/// Allow(vec![Method::GET])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate http;
|
|
||||||
/// # extern crate actix_http;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::Allow;
|
/// use actix_http::http::{header::Allow, Method};
|
||||||
/// use http::Method;
|
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// Allow(vec![
|
/// Allow(vec![
|
||||||
/// Method::GET,
|
/// Method::GET,
|
||||||
/// Method::POST,
|
/// Method::POST,
|
||||||
/// Method::PATCH,
|
/// Method::PATCH,
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
(Allow, header::ALLOW) => (Method)*
|
(Allow, header::ALLOW) => (Method)*
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,12 @@ use crate::header::{
|
||||||
/// * `max-age=30`
|
/// * `max-age=30`
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{CacheControl, CacheDirective};
|
/// use actix_http::http::header::{CacheControl, CacheDirective};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(CacheControl(vec![CacheDirective::MaxAge(86400u32)]));
|
/// builder.insert_header(CacheControl(vec![CacheDirective::MaxAge(86400u32)]));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -41,7 +41,7 @@ use crate::header::{
|
||||||
/// use actix_http::http::header::{CacheControl, CacheDirective};
|
/// use actix_http::http::header::{CacheControl, CacheDirective};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(CacheControl(vec![
|
/// builder.insert_header(CacheControl(vec![
|
||||||
/// CacheDirective::NoCache,
|
/// CacheDirective::NoCache,
|
||||||
/// CacheDirective::Private,
|
/// CacheDirective::Private,
|
||||||
/// CacheDirective::MaxAge(360u32),
|
/// CacheDirective::MaxAge(360u32),
|
||||||
|
@ -196,7 +196,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_multiple_headers() {
|
fn test_parse_multiple_headers() {
|
||||||
let req = TestRequest::default().insert_header(header::CACHE_CONTROL, "no-cache, private")
|
let req = TestRequest::default()
|
||||||
|
.insert_header((header::CACHE_CONTROL, "no-cache, private"))
|
||||||
.finish();
|
.finish();
|
||||||
let cache = Header::parse(&req);
|
let cache = Header::parse(&req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -210,9 +211,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_argument() {
|
fn test_parse_argument() {
|
||||||
let req =
|
let req = TestRequest::default()
|
||||||
TestRequest::default().insert_header(header::CACHE_CONTROL, "max-age=100, private")
|
.insert_header((header::CACHE_CONTROL, "max-age=100, private"))
|
||||||
.finish();
|
.finish();
|
||||||
let cache = Header::parse(&req);
|
let cache = Header::parse(&req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cache.ok(),
|
cache.ok(),
|
||||||
|
@ -225,8 +226,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_quote_form() {
|
fn test_parse_quote_form() {
|
||||||
let req =
|
let req = TestRequest::default()
|
||||||
TestRequest::default().insert_header(header::CACHE_CONTROL, "max-age=\"200\"").finish();
|
.insert_header((header::CACHE_CONTROL, "max-age=\"200\""))
|
||||||
|
.finish();
|
||||||
let cache = Header::parse(&req);
|
let cache = Header::parse(&req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cache.ok(),
|
cache.ok(),
|
||||||
|
@ -236,8 +238,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_extension() {
|
fn test_parse_extension() {
|
||||||
let req =
|
let req = TestRequest::default()
|
||||||
TestRequest::default().insert_header(header::CACHE_CONTROL, "foo, bar=baz").finish();
|
.insert_header((header::CACHE_CONTROL, "foo, bar=baz"))
|
||||||
|
.finish();
|
||||||
let cache = Header::parse(&req);
|
let cache = Header::parse(&req);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cache.ok(),
|
cache.ok(),
|
||||||
|
@ -250,7 +253,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_bad_syntax() {
|
fn test_parse_bad_syntax() {
|
||||||
let req = TestRequest::default().insert_header(header::CACHE_CONTROL, "foo=").finish();
|
let req = TestRequest::default()
|
||||||
|
.insert_header((header::CACHE_CONTROL, "foo="))
|
||||||
|
.finish();
|
||||||
let cache: Result<CacheControl, _> = Header::parse(&req);
|
let cache: Result<CacheControl, _> = Header::parse(&req);
|
||||||
assert_eq!(cache.ok(), None)
|
assert_eq!(cache.ok(), None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,38 +23,31 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
/// use language_tags::langtag;
|
||||||
/// # #[macro_use] extern crate language_tags;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// # use actix_http::http::header::{ContentLanguage, qitem};
|
/// use actix_http::http::header::{ContentLanguage, qitem};
|
||||||
/// #
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// ContentLanguage(vec![
|
/// ContentLanguage(vec![
|
||||||
/// qitem(langtag!(en)),
|
/// qitem(langtag!(en)),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate actix_http;
|
/// use language_tags::langtag;
|
||||||
/// # #[macro_use] extern crate language_tags;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// # use actix_http::http::header::{ContentLanguage, qitem};
|
/// use actix_http::http::header::{ContentLanguage, qitem};
|
||||||
/// #
|
|
||||||
/// # fn main() {
|
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// ContentLanguage(vec![
|
/// ContentLanguage(vec![
|
||||||
/// qitem(langtag!(da)),
|
/// qitem(langtag!(da)),
|
||||||
/// qitem(langtag!(en;;;GB)),
|
/// qitem(langtag!(en;;;GB)),
|
||||||
/// ])
|
/// ])
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
||||||
|
|
||||||
|
|
|
@ -30,31 +30,24 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::ContentType;
|
/// use actix_http::http::header::ContentType;
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// ContentType::json()
|
/// ContentType::json()
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// # extern crate mime;
|
|
||||||
/// # extern crate actix_http;
|
|
||||||
/// use mime::TEXT_HTML;
|
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::ContentType;
|
/// use actix_http::http::header::ContentType;
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// ContentType(TEXT_HTML)
|
/// ContentType(mime::TEXT_HTML)
|
||||||
/// );
|
/// );
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
(ContentType, CONTENT_TYPE) => [Mime]
|
(ContentType, CONTENT_TYPE) => [Mime]
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,15 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
|
/// use std::time::SystemTime;
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::Date;
|
/// use actix_http::http::header::Date;
|
||||||
/// use std::time::SystemTime;
|
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(Date(SystemTime::now().into()));
|
/// builder.insert_header(
|
||||||
|
/// Date(SystemTime::now().into())
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
(Date, DATE) => [HttpDate]
|
(Date, DATE) => [HttpDate]
|
||||||
|
|
||||||
|
|
|
@ -27,20 +27,24 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{ETag, EntityTag};
|
/// use actix_http::http::header::{ETag, EntityTag};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(ETag(EntityTag::new(false, "xyzzy".to_owned())));
|
/// builder.insert_header(
|
||||||
|
/// ETag(EntityTag::new(false, "xyzzy".to_owned()))
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{ETag, EntityTag};
|
/// use actix_http::http::header::{ETag, EntityTag};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(ETag(EntityTag::new(true, "xyzzy".to_owned())));
|
/// builder.insert_header(
|
||||||
|
/// ETag(EntityTag::new(true, "xyzzy".to_owned()))
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
(ETag, ETAG) => [EntityTag]
|
(ETag, ETAG) => [EntityTag]
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,16 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
|
/// use std::time::{SystemTime, Duration};
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::Expires;
|
/// use actix_http::http::header::Expires;
|
||||||
/// use std::time::{SystemTime, Duration};
|
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// let expiration = SystemTime::now() + Duration::from_secs(60 * 60 * 24);
|
/// let expiration = SystemTime::now() + Duration::from_secs(60 * 60 * 24);
|
||||||
/// builder.set(Expires(expiration.into()));
|
/// builder.insert_header(
|
||||||
|
/// Expires(expiration.into())
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
(Expires, EXPIRES) => [HttpDate]
|
(Expires, EXPIRES) => [HttpDate]
|
||||||
|
|
||||||
|
|
|
@ -29,20 +29,20 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::IfMatch;
|
/// use actix_http::http::header::IfMatch;
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(IfMatch::Any);
|
/// builder.insert_header(IfMatch::Any);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{IfMatch, EntityTag};
|
/// use actix_http::http::header::{IfMatch, EntityTag};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// IfMatch::Items(vec![
|
/// IfMatch::Items(vec![
|
||||||
/// EntityTag::new(false, "xyzzy".to_owned()),
|
/// EntityTag::new(false, "xyzzy".to_owned()),
|
||||||
/// EntityTag::new(false, "foobar".to_owned()),
|
/// EntityTag::new(false, "foobar".to_owned()),
|
||||||
|
|
|
@ -21,14 +21,16 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
|
/// use std::time::{SystemTime, Duration};
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::IfModifiedSince;
|
/// use actix_http::http::header::IfModifiedSince;
|
||||||
/// use std::time::{SystemTime, Duration};
|
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
||||||
/// builder.set(IfModifiedSince(modified.into()));
|
/// builder.insert_header(
|
||||||
|
/// IfModifiedSince(modified.into())
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
(IfModifiedSince, IF_MODIFIED_SINCE) => [HttpDate]
|
(IfModifiedSince, IF_MODIFIED_SINCE) => [HttpDate]
|
||||||
|
|
||||||
|
|
|
@ -31,20 +31,20 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::IfNoneMatch;
|
/// use actix_http::http::header::IfNoneMatch;
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(IfNoneMatch::Any);
|
/// builder.insert_header(IfNoneMatch::Any);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{IfNoneMatch, EntityTag};
|
/// use actix_http::http::header::{IfNoneMatch, EntityTag};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(
|
/// builder.insert_header(
|
||||||
/// IfNoneMatch::Items(vec![
|
/// IfNoneMatch::Items(vec![
|
||||||
/// EntityTag::new(false, "xyzzy".to_owned()),
|
/// EntityTag::new(false, "xyzzy".to_owned()),
|
||||||
/// EntityTag::new(false, "foobar".to_owned()),
|
/// EntityTag::new(false, "foobar".to_owned()),
|
||||||
|
@ -73,13 +73,15 @@ mod tests {
|
||||||
fn test_if_none_match() {
|
fn test_if_none_match() {
|
||||||
let mut if_none_match: Result<IfNoneMatch, _>;
|
let mut if_none_match: Result<IfNoneMatch, _>;
|
||||||
|
|
||||||
let req = TestRequest::default().insert_header(IF_NONE_MATCH, "*").finish();
|
let req = TestRequest::default()
|
||||||
|
.insert_header((IF_NONE_MATCH, "*"))
|
||||||
|
.finish();
|
||||||
if_none_match = Header::parse(&req);
|
if_none_match = Header::parse(&req);
|
||||||
assert_eq!(if_none_match.ok(), Some(IfNoneMatch::Any));
|
assert_eq!(if_none_match.ok(), Some(IfNoneMatch::Any));
|
||||||
|
|
||||||
let req =
|
let req = TestRequest::default()
|
||||||
TestRequest::default().insert_header(IF_NONE_MATCH, &b"\"foobar\", W/\"weak-etag\""[..])
|
.insert_header((IF_NONE_MATCH, &b"\"foobar\", W/\"weak-etag\""[..]))
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
if_none_match = Header::parse(&req);
|
if_none_match = Header::parse(&req);
|
||||||
let mut entities: Vec<EntityTag> = Vec::new();
|
let mut entities: Vec<EntityTag> = Vec::new();
|
||||||
|
|
|
@ -35,24 +35,27 @@ use crate::httpmessage::HttpMessage;
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::{EntityTag, IfRange};
|
/// use actix_http::http::header::{EntityTag, IfRange};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// builder.set(IfRange::EntityTag(EntityTag::new(
|
/// builder.insert_header(
|
||||||
/// false,
|
/// IfRange::EntityTag(
|
||||||
/// "abc".to_owned(),
|
/// EntityTag::new(false, "abc".to_owned())
|
||||||
/// )));
|
/// )
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use std::time::{Duration, SystemTime};
|
/// use std::time::{Duration, SystemTime};
|
||||||
/// use actix_http::{http::header::IfRange, Response};
|
/// use actix_http::{http::header::IfRange, Response};
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// let fetched = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
/// let fetched = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
||||||
/// builder.set(IfRange::Date(fetched.into()));
|
/// builder.insert_header(
|
||||||
|
/// IfRange::Date(fetched.into())
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum IfRange {
|
pub enum IfRange {
|
||||||
|
|
|
@ -22,14 +22,16 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
|
/// use std::time::{SystemTime, Duration};
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::IfUnmodifiedSince;
|
/// use actix_http::http::header::IfUnmodifiedSince;
|
||||||
/// use std::time::{SystemTime, Duration};
|
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
||||||
/// builder.set(IfUnmodifiedSince(modified.into()));
|
/// builder.insert_header(
|
||||||
|
/// IfUnmodifiedSince(modified.into())
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
(IfUnmodifiedSince, IF_UNMODIFIED_SINCE) => [HttpDate]
|
(IfUnmodifiedSince, IF_UNMODIFIED_SINCE) => [HttpDate]
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,16 @@ header! {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
|
/// use std::time::{SystemTime, Duration};
|
||||||
/// use actix_http::Response;
|
/// use actix_http::Response;
|
||||||
/// use actix_http::http::header::LastModified;
|
/// use actix_http::http::header::LastModified;
|
||||||
/// use std::time::{SystemTime, Duration};
|
|
||||||
///
|
///
|
||||||
/// let mut builder = Response::Ok();
|
/// let mut builder = Response::Ok();
|
||||||
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
||||||
/// builder.set(LastModified(modified.into()));
|
/// builder.insert_header(
|
||||||
|
/// LastModified(modified.into())
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
(LastModified, LAST_MODIFIED) => [HttpDate]
|
(LastModified, LAST_MODIFIED) => [HttpDate]
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ macro_rules! test_header {
|
||||||
let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
|
let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
|
||||||
let mut req = test::TestRequest::default();
|
let mut req = test::TestRequest::default();
|
||||||
for item in a {
|
for item in a {
|
||||||
req = req.header(HeaderField::name(), item).take();
|
req = req.insert_header((HeaderField::name(), item)).take();
|
||||||
}
|
}
|
||||||
let req = req.finish();
|
let req = req.finish();
|
||||||
let value = HeaderField::parse(&req);
|
let value = HeaderField::parse(&req);
|
||||||
|
@ -111,7 +111,7 @@ macro_rules! test_header {
|
||||||
let a: Vec<Vec<u8>> = $raw.iter().map(|x| x.to_vec()).collect();
|
let a: Vec<Vec<u8>> = $raw.iter().map(|x| x.to_vec()).collect();
|
||||||
let mut req = test::TestRequest::default();
|
let mut req = test::TestRequest::default();
|
||||||
for item in a {
|
for item in a {
|
||||||
req.header(HeaderField::name(), item);
|
req.insert_header((HeaderField::name(), item));
|
||||||
}
|
}
|
||||||
let req = req.finish();
|
let req = req.finish();
|
||||||
let val = HeaderField::parse(&req);
|
let val = HeaderField::parse(&req);
|
||||||
|
@ -334,7 +334,7 @@ macro_rules! header {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod accept_charset;
|
mod accept_charset;
|
||||||
//mod accept_encoding;
|
// mod accept_encoding;
|
||||||
mod accept;
|
mod accept;
|
||||||
mod accept_language;
|
mod accept_language;
|
||||||
mod allow;
|
mod allow;
|
||||||
|
|
|
@ -174,11 +174,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_content_type() {
|
fn test_content_type() {
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "text/plain")
|
.insert_header(("content-type", "text/plain"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(req.content_type(), "text/plain");
|
assert_eq!(req.content_type(), "text/plain");
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "application/json; charset=utf=8")
|
.insert_header(("content-type", "application/json; charset=utf=8"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(req.content_type(), "application/json");
|
assert_eq!(req.content_type(), "application/json");
|
||||||
let req = TestRequest::default().finish();
|
let req = TestRequest::default().finish();
|
||||||
|
@ -188,13 +188,13 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mime_type() {
|
fn test_mime_type() {
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "application/json")
|
.insert_header(("content-type", "application/json"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(req.mime_type().unwrap(), Some(mime::APPLICATION_JSON));
|
assert_eq!(req.mime_type().unwrap(), Some(mime::APPLICATION_JSON));
|
||||||
let req = TestRequest::default().finish();
|
let req = TestRequest::default().finish();
|
||||||
assert_eq!(req.mime_type().unwrap(), None);
|
assert_eq!(req.mime_type().unwrap(), None);
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "application/json; charset=utf-8")
|
.insert_header(("content-type", "application/json; charset=utf-8"))
|
||||||
.finish();
|
.finish();
|
||||||
let mt = req.mime_type().unwrap().unwrap();
|
let mt = req.mime_type().unwrap().unwrap();
|
||||||
assert_eq!(mt.get_param(mime::CHARSET), Some(mime::UTF_8));
|
assert_eq!(mt.get_param(mime::CHARSET), Some(mime::UTF_8));
|
||||||
|
@ -205,7 +205,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mime_type_error() {
|
fn test_mime_type_error() {
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "applicationadfadsfasdflknadsfklnadsfjson")
|
.insert_header(("content-type", "applicationadfadsfasdflknadsfklnadsfjson"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(Err(ContentTypeError::ParseError), req.mime_type());
|
assert_eq!(Err(ContentTypeError::ParseError), req.mime_type());
|
||||||
}
|
}
|
||||||
|
@ -216,12 +216,12 @@ mod tests {
|
||||||
assert_eq!(UTF_8.name(), req.encoding().unwrap().name());
|
assert_eq!(UTF_8.name(), req.encoding().unwrap().name());
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "application/json")
|
.insert_header(("content-type", "application/json"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(UTF_8.name(), req.encoding().unwrap().name());
|
assert_eq!(UTF_8.name(), req.encoding().unwrap().name());
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "application/json; charset=ISO-8859-2")
|
.insert_header(("content-type", "application/json; charset=ISO-8859-2"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(ISO_8859_2, req.encoding().unwrap());
|
assert_eq!(ISO_8859_2, req.encoding().unwrap());
|
||||||
}
|
}
|
||||||
|
@ -229,12 +229,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_encoding_error() {
|
fn test_encoding_error() {
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "applicatjson")
|
.insert_header(("content-type", "applicatjson"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(Some(ContentTypeError::ParseError), req.encoding().err());
|
assert_eq!(Some(ContentTypeError::ParseError), req.encoding().err());
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header("content-type", "application/json; charset=kkkttktk")
|
.insert_header(("content-type", "application/json; charset=kkkttktk"))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Some(ContentTypeError::UnknownEncoding),
|
Some(ContentTypeError::UnknownEncoding),
|
||||||
|
@ -248,15 +248,15 @@ mod tests {
|
||||||
assert!(!req.chunked().unwrap());
|
assert!(!req.chunked().unwrap());
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header(header::TRANSFER_ENCODING, "chunked")
|
.insert_header((header::TRANSFER_ENCODING, "chunked"))
|
||||||
.finish();
|
.finish();
|
||||||
assert!(req.chunked().unwrap());
|
assert!(req.chunked().unwrap());
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::TRANSFER_ENCODING,
|
header::TRANSFER_ENCODING,
|
||||||
Bytes::from_static(b"some va\xadscc\xacas0xsdasdlue"),
|
Bytes::from_static(b"some va\xadscc\xacas0xsdasdlue"),
|
||||||
)
|
))
|
||||||
.finish();
|
.finish();
|
||||||
assert!(req.chunked().is_err());
|
assert!(req.chunked().is_err());
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,10 +348,12 @@ impl ResponseBuilder {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use actix_http::Response;
|
/// # use actix_http::Response;
|
||||||
|
///
|
||||||
|
/// use actix_http::http::header::ContentType;
|
||||||
/// Response::Ok()
|
/// Response::Ok()
|
||||||
/// .set_header(("X-TEST", "value"))
|
/// .insert_header(("X-TEST", "value"))
|
||||||
/// .set_header(ContentType(mime::APPLICATION_JSON))
|
/// .insert_header(ContentType(mime::APPLICATION_JSON))
|
||||||
/// .finish()
|
/// .finish();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn insert_header<H>(&mut self, header: H) -> &mut Self
|
pub fn insert_header<H>(&mut self, header: H) -> &mut Self
|
||||||
where
|
where
|
||||||
|
@ -371,10 +373,12 @@ impl ResponseBuilder {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use actix_http::Response;
|
/// # use actix_http::Response;
|
||||||
|
/// use actix_http::http::header::ContentType;
|
||||||
|
///
|
||||||
/// Response::Ok()
|
/// Response::Ok()
|
||||||
/// .append_header(("X-TEST", "value"))
|
/// .append_header(("X-TEST", "value"))
|
||||||
/// .append_header(ContentType(mime::APPLICATION_JSON))
|
/// .append_header(ContentType(mime::APPLICATION_JSON))
|
||||||
/// .finish()
|
/// .finish();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn append_header<H>(&mut self, header: H) -> &mut Self
|
pub fn append_header<H>(&mut self, header: H) -> &mut Self
|
||||||
where
|
where
|
||||||
|
@ -822,8 +826,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_debug() {
|
fn test_debug() {
|
||||||
let resp = Response::Ok()
|
let resp = Response::Ok()
|
||||||
.header(COOKIE, HeaderValue::from_static("cookie1=value1; "))
|
.append_header((COOKIE, HeaderValue::from_static("cookie1=value1; ")))
|
||||||
.header(COOKIE, HeaderValue::from_static("cookie2=value2; "))
|
.append_header((COOKIE, HeaderValue::from_static("cookie2=value2; ")))
|
||||||
.finish();
|
.finish();
|
||||||
let dbg = format!("{:?}", resp);
|
let dbg = format!("{:?}", resp);
|
||||||
assert!(dbg.contains("Response"));
|
assert!(dbg.contains("Response"));
|
||||||
|
@ -834,8 +838,8 @@ mod tests {
|
||||||
use crate::httpmessage::HttpMessage;
|
use crate::httpmessage::HttpMessage;
|
||||||
|
|
||||||
let req = crate::test::TestRequest::default()
|
let req = crate::test::TestRequest::default()
|
||||||
.header(COOKIE, "cookie1=value1")
|
.append_header((COOKIE, "cookie1=value1"))
|
||||||
.header(COOKIE, "cookie2=value2")
|
.append_header((COOKIE, "cookie2=value2"))
|
||||||
.finish();
|
.finish();
|
||||||
let cookies = req.cookies().unwrap();
|
let cookies = req.cookies().unwrap();
|
||||||
|
|
||||||
|
@ -889,7 +893,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic_builder() {
|
fn test_basic_builder() {
|
||||||
let resp = Response::Ok().header("X-TEST", "value").finish();
|
let resp = Response::Ok().insert_header(("X-TEST", "value")).finish();
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -930,7 +934,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_json_ct() {
|
fn test_json_ct() {
|
||||||
let resp = Response::build(StatusCode::OK)
|
let resp = Response::build(StatusCode::OK)
|
||||||
.header(CONTENT_TYPE, "text/json")
|
.insert_header((CONTENT_TYPE, "text/json"))
|
||||||
.json(vec!["v1", "v2", "v3"]);
|
.json(vec!["v1", "v2", "v3"]);
|
||||||
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
|
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
|
||||||
assert_eq!(ct, HeaderValue::from_static("text/json"));
|
assert_eq!(ct, HeaderValue::from_static("text/json"));
|
||||||
|
@ -948,7 +952,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_json2_ct() {
|
fn test_json2_ct() {
|
||||||
let resp = Response::build(StatusCode::OK)
|
let resp = Response::build(StatusCode::OK)
|
||||||
.header(CONTENT_TYPE, "text/json")
|
.insert_header((CONTENT_TYPE, "text/json"))
|
||||||
.json2(&vec!["v1", "v2", "v3"]);
|
.json2(&vec!["v1", "v2", "v3"]);
|
||||||
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
|
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
|
||||||
assert_eq!(ct, HeaderValue::from_static("text/json"));
|
assert_eq!(ct, HeaderValue::from_static("text/json"));
|
||||||
|
|
|
@ -224,7 +224,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(header::UPGRADE, header::HeaderValue::from_static("test"))
|
.insert_header((header::UPGRADE, header::HeaderValue::from_static("test")))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoWebsocketUpgrade,
|
HandshakeError::NoWebsocketUpgrade,
|
||||||
|
@ -232,10 +232,10 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoConnectionUpgrade,
|
HandshakeError::NoConnectionUpgrade,
|
||||||
|
@ -243,14 +243,14 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoVersionHeader,
|
HandshakeError::NoVersionHeader,
|
||||||
|
@ -258,18 +258,18 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("5"),
|
header::HeaderValue::from_static("5"),
|
||||||
)
|
))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::UnsupportedVersion,
|
HandshakeError::UnsupportedVersion,
|
||||||
|
@ -277,18 +277,18 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::BadWebsocketKey,
|
HandshakeError::BadWebsocketKey,
|
||||||
|
@ -296,22 +296,22 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_KEY,
|
header::SEC_WEBSOCKET_KEY,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.finish();
|
.finish();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
StatusCode::SWITCHING_PROTOCOLS,
|
StatusCode::SWITCHING_PROTOCOLS,
|
||||||
|
|
|
@ -38,7 +38,7 @@ async fn test_h1_v2() {
|
||||||
let response = srv.get("/").send().await.unwrap();
|
let response = srv.get("/").send().await.unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
let request = srv.get("/").header("x-test", "111").send();
|
let request = srv.get("/").insert_header(("x-test", "111")).send();
|
||||||
let mut response = request.await.unwrap();
|
let mut response = request.await.unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
|
|
|
@ -173,8 +173,8 @@ async fn test_h2_headers() {
|
||||||
HttpService::build().h2(move |_| {
|
HttpService::build().h2(move |_| {
|
||||||
let mut builder = Response::Ok();
|
let mut builder = Response::Ok();
|
||||||
for idx in 0..90 {
|
for idx in 0..90 {
|
||||||
builder.header(
|
builder.insert_header(
|
||||||
format!("X-TEST-{}", idx).as_str(),
|
(format!("X-TEST-{}", idx).as_str(),
|
||||||
"TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
"TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
|
@ -188,7 +188,7 @@ async fn test_h2_headers() {
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST ",
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST ",
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
ok::<_, ()>(builder.body(data.clone()))
|
ok::<_, ()>(builder.body(data.clone()))
|
||||||
})
|
})
|
||||||
|
@ -341,7 +341,7 @@ async fn test_h2_body_chunked_explicit() {
|
||||||
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
|
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
|
||||||
ok::<_, ()>(
|
ok::<_, ()>(
|
||||||
Response::Ok()
|
Response::Ok()
|
||||||
.header(header::TRANSFER_ENCODING, "chunked")
|
.insert_header((header::TRANSFER_ENCODING, "chunked"))
|
||||||
.streaming(body),
|
.streaming(body),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -369,7 +369,7 @@ async fn test_h2_response_http_error_handling() {
|
||||||
let broken_header = Bytes::from_static(b"\0\0\0");
|
let broken_header = Bytes::from_static(b"\0\0\0");
|
||||||
ok::<_, ()>(
|
ok::<_, ()>(
|
||||||
Response::Ok()
|
Response::Ok()
|
||||||
.header(header::CONTENT_TYPE, broken_header)
|
.insert_header((header::CONTENT_TYPE, broken_header))
|
||||||
.body(STR),
|
.body(STR),
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -392,7 +392,7 @@ async fn test_h1_headers() {
|
||||||
HttpService::build().h1(move |_| {
|
HttpService::build().h1(move |_| {
|
||||||
let mut builder = Response::Ok();
|
let mut builder = Response::Ok();
|
||||||
for idx in 0..90 {
|
for idx in 0..90 {
|
||||||
builder.header(
|
builder.insert_header((
|
||||||
format!("X-TEST-{}", idx).as_str(),
|
format!("X-TEST-{}", idx).as_str(),
|
||||||
"TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
"TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
|
@ -407,7 +407,7 @@ async fn test_h1_headers() {
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST \
|
||||||
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST ",
|
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST ",
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
future::ok::<_, ()>(builder.body(data.clone()))
|
future::ok::<_, ()>(builder.body(data.clone()))
|
||||||
}).tcp()
|
}).tcp()
|
||||||
|
@ -561,7 +561,7 @@ async fn test_h1_body_chunked_explicit() {
|
||||||
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
|
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
|
||||||
ok::<_, ()>(
|
ok::<_, ()>(
|
||||||
Response::Ok()
|
Response::Ok()
|
||||||
.header(header::TRANSFER_ENCODING, "chunked")
|
.insert_header((header::TRANSFER_ENCODING, "chunked"))
|
||||||
.streaming(body),
|
.streaming(body),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -625,7 +625,7 @@ async fn test_h1_response_http_error_handling() {
|
||||||
let broken_header = Bytes::from_static(b"\0\0\0");
|
let broken_header = Bytes::from_static(b"\0\0\0");
|
||||||
ok::<_, ()>(
|
ok::<_, ()>(
|
||||||
Response::Ok()
|
Response::Ok()
|
||||||
.header(http::header::CONTENT_TYPE, broken_header)
|
.insert_header((http::header::CONTENT_TYPE, broken_header))
|
||||||
.body(STR),
|
.body(STR),
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -166,11 +166,11 @@ pub fn handshake_with_protocols(
|
||||||
|
|
||||||
let mut response = HttpResponse::build(StatusCode::SWITCHING_PROTOCOLS)
|
let mut response = HttpResponse::build(StatusCode::SWITCHING_PROTOCOLS)
|
||||||
.upgrade("websocket")
|
.upgrade("websocket")
|
||||||
.header(header::SEC_WEBSOCKET_ACCEPT, key.as_str())
|
.insert_header((header::SEC_WEBSOCKET_ACCEPT, key))
|
||||||
.take();
|
.take();
|
||||||
|
|
||||||
if let Some(protocol) = protocol {
|
if let Some(protocol) = protocol {
|
||||||
response.header(&header::SEC_WEBSOCKET_PROTOCOL, protocol);
|
response.insert_header((header::SEC_WEBSOCKET_PROTOCOL, protocol));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
|
@ -573,7 +573,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(header::UPGRADE, header::HeaderValue::from_static("test"))
|
.insert_header((header::UPGRADE, header::HeaderValue::from_static("test")))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoWebsocketUpgrade,
|
HandshakeError::NoWebsocketUpgrade,
|
||||||
|
@ -581,10 +581,10 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoConnectionUpgrade,
|
HandshakeError::NoConnectionUpgrade,
|
||||||
|
@ -592,14 +592,14 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoVersionHeader,
|
HandshakeError::NoVersionHeader,
|
||||||
|
@ -607,18 +607,18 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("5"),
|
header::HeaderValue::from_static("5"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::UnsupportedVersion,
|
HandshakeError::UnsupportedVersion,
|
||||||
|
@ -626,18 +626,18 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::BadWebsocketKey,
|
HandshakeError::BadWebsocketKey,
|
||||||
|
@ -645,22 +645,22 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_KEY,
|
header::SEC_WEBSOCKET_KEY,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
let resp = handshake(&req).unwrap().finish();
|
let resp = handshake(&req).unwrap().finish();
|
||||||
|
@ -669,26 +669,26 @@ mod tests {
|
||||||
assert_eq!(None, resp.headers().get(&header::TRANSFER_ENCODING));
|
assert_eq!(None, resp.headers().get(&header::TRANSFER_ENCODING));
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_KEY,
|
header::SEC_WEBSOCKET_KEY,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_PROTOCOL,
|
header::SEC_WEBSOCKET_PROTOCOL,
|
||||||
header::HeaderValue::from_static("graphql"),
|
header::HeaderValue::from_static("graphql"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
let protocols = ["graphql"];
|
let protocols = ["graphql"];
|
||||||
|
@ -710,26 +710,26 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_KEY,
|
header::SEC_WEBSOCKET_KEY,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_PROTOCOL,
|
header::SEC_WEBSOCKET_PROTOCOL,
|
||||||
header::HeaderValue::from_static("p1, p2, p3"),
|
header::HeaderValue::from_static("p1, p2, p3"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
let protocols = vec!["p3", "p2"];
|
let protocols = vec!["p3", "p2"];
|
||||||
|
@ -751,26 +751,26 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.header(
|
.insert_header((
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_KEY,
|
header::SEC_WEBSOCKET_KEY,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
))
|
||||||
.header(
|
.insert_header((
|
||||||
header::SEC_WEBSOCKET_PROTOCOL,
|
header::SEC_WEBSOCKET_PROTOCOL,
|
||||||
header::HeaderValue::from_static("p1,p2,p3"),
|
header::HeaderValue::from_static("p1,p2,p3"),
|
||||||
)
|
))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
|
|
||||||
let protocols = vec!["p3", "p2"];
|
let protocols = vec!["p3", "p2"];
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
||||||
//! let mut client = awc::Client::default();
|
//! let mut client = awc::Client::default();
|
||||||
//! let response = client.get("http://www.rust-lang.org") // <- Create request builder
|
//! let response = client.get("http://www.rust-lang.org") // <- Create request builder
|
||||||
//! .header("User-Agent", "Actix-web")
|
//! .insert_header(("User-Agent", "Actix-web"))
|
||||||
//! .send() // <- Send http request
|
//! .send() // <- Send http request
|
||||||
//! .await?;
|
//! .await?;
|
||||||
//!
|
//!
|
||||||
|
@ -134,7 +134,7 @@ use self::connect::{Connect, ConnectorWrapper};
|
||||||
/// let mut client = Client::default();
|
/// let mut client = Client::default();
|
||||||
///
|
///
|
||||||
/// let res = client.get("http://www.rust-lang.org") // <- Create request builder
|
/// let res = client.get("http://www.rust-lang.org") // <- Create request builder
|
||||||
/// .header("User-Agent", "Actix-web")
|
/// .insert_header(("User-Agent", "Actix-web"))
|
||||||
/// .send() // <- Send http request
|
/// .send() // <- Send http request
|
||||||
/// .await; // <- send request and wait for response
|
/// .await; // <- send request and wait for response
|
||||||
///
|
///
|
||||||
|
|
|
@ -37,13 +37,11 @@ cfg_if::cfg_if! {
|
||||||
/// builder-like pattern.
|
/// builder-like pattern.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use actix_rt::System;
|
|
||||||
///
|
|
||||||
/// #[actix_rt::main]
|
/// #[actix_rt::main]
|
||||||
/// async fn main() {
|
/// async fn main() {
|
||||||
/// let response = awc::Client::new()
|
/// let response = awc::Client::new()
|
||||||
/// .get("http://www.rust-lang.org") // <- Create request builder
|
/// .get("http://www.rust-lang.org") // <- Create request builder
|
||||||
/// .header("User-Agent", "Actix-web")
|
/// .insert_header(("User-Agent", "Actix-web"))
|
||||||
/// .send() // <- Send http request
|
/// .send() // <- Send http request
|
||||||
/// .await;
|
/// .await;
|
||||||
///
|
///
|
||||||
|
@ -188,17 +186,16 @@ impl ClientRequest {
|
||||||
/// Append a header, keeping any that were set with an equivalent field name.
|
/// Append a header, keeping any that were set with an equivalent field name.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use awc::{http, Client};
|
/// # #[actix_rt::main]
|
||||||
|
/// # async fn main() {
|
||||||
|
/// # use awc::Client;
|
||||||
|
/// use awc::http::header::ContentType;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// Client::new()
|
||||||
/// # actix_rt::System::new("test").block_on(async {
|
/// .get("http://www.rust-lang.org")
|
||||||
/// let req = Client::new()
|
/// .insert_header(("X-TEST", "value"))
|
||||||
/// .get("http://www.rust-lang.org")
|
/// .insert_header(ContentType(mime::APPLICATION_JSON));
|
||||||
/// .header("X-TEST", "value")
|
/// # }
|
||||||
/// .header(http::header::CONTENT_TYPE, "application/json");
|
|
||||||
/// # Ok::<_, ()>(())
|
|
||||||
/// # });
|
|
||||||
/// }
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn append_header<H>(mut self, header: H) -> Self
|
pub fn append_header<H>(mut self, header: H) -> Self
|
||||||
where
|
where
|
||||||
|
@ -560,7 +557,7 @@ mod tests {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_debug() {
|
async fn test_debug() {
|
||||||
let request = Client::new().get("/").append_header("x-test", "111");
|
let request = Client::new().get("/").append_header(("x-test", "111"));
|
||||||
let repr = format!("{:?}", request);
|
let repr = format!("{:?}", request);
|
||||||
assert!(repr.contains("ClientRequest"));
|
assert!(repr.contains("ClientRequest"));
|
||||||
assert!(repr.contains("x-test"));
|
assert!(repr.contains("x-test"));
|
||||||
|
@ -571,18 +568,18 @@ mod tests {
|
||||||
let req = Client::new()
|
let req = Client::new()
|
||||||
.put("/")
|
.put("/")
|
||||||
.version(Version::HTTP_2)
|
.version(Version::HTTP_2)
|
||||||
.set(header::Date(SystemTime::now().into()))
|
.insert_header(header::Date(SystemTime::now().into()))
|
||||||
.content_type("plain/text")
|
.content_type("plain/text")
|
||||||
.append_header(header::SERVER, "awc");
|
.append_header((header::SERVER, "awc"));
|
||||||
|
|
||||||
let req = if let Some(val) = Some("server") {
|
let req = if let Some(val) = Some("server") {
|
||||||
req.append_header(header::USER_AGENT, val)
|
req.append_header((header::USER_AGENT, val))
|
||||||
} else {
|
} else {
|
||||||
req
|
req
|
||||||
};
|
};
|
||||||
|
|
||||||
let req = if let Some(_val) = Option::<&str>::None {
|
let req = if let Some(_val) = Option::<&str>::None {
|
||||||
req.append_header(header::ALLOW, "1")
|
req.append_header((header::ALLOW, "1"))
|
||||||
} else {
|
} else {
|
||||||
req
|
req
|
||||||
};
|
};
|
||||||
|
@ -625,7 +622,7 @@ mod tests {
|
||||||
.header(header::CONTENT_TYPE, "111")
|
.header(header::CONTENT_TYPE, "111")
|
||||||
.finish()
|
.finish()
|
||||||
.get("/")
|
.get("/")
|
||||||
.insert_header(header::CONTENT_TYPE, "222");
|
.insert_header((header::CONTENT_TYPE, "222"));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
req.head
|
req.head
|
||||||
|
|
|
@ -52,7 +52,7 @@ async fn test_simple() {
|
||||||
.service(web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))))
|
.service(web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR))))
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv.get("/").append_header("x-test", "111").send();
|
let request = srv.get("/").insert_header(("x-test", "111")).send();
|
||||||
let mut response = request.await.unwrap();
|
let mut response = request.await.unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ async fn test_json() {
|
||||||
|
|
||||||
let request = srv
|
let request = srv
|
||||||
.get("/")
|
.get("/")
|
||||||
.append_header("x-test", "111")
|
.insert_header(("x-test", "111"))
|
||||||
.send_json(&"TEST".to_string());
|
.send_json(&"TEST".to_string());
|
||||||
let response = request.await.unwrap();
|
let response = request.await.unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
@ -99,7 +99,10 @@ async fn test_form() {
|
||||||
let mut data = HashMap::new();
|
let mut data = HashMap::new();
|
||||||
let _ = data.insert("key".to_string(), "TEST".to_string());
|
let _ = data.insert("key".to_string(), "TEST".to_string());
|
||||||
|
|
||||||
let request = srv.get("/").append_header("x-test", "111").send_form(&data);
|
let request = srv
|
||||||
|
.get("/")
|
||||||
|
.append_header(("x-test", "111"))
|
||||||
|
.send_form(&data);
|
||||||
let response = request.await.unwrap();
|
let response = request.await.unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
}
|
}
|
||||||
|
@ -438,7 +441,7 @@ async fn test_client_gzip_encoding() {
|
||||||
let data = e.finish().unwrap();
|
let data = e.finish().unwrap();
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.header("content-encoding", "gzip")
|
.insert_header(("content-encoding", "gzip"))
|
||||||
.body(data)
|
.body(data)
|
||||||
})))
|
})))
|
||||||
});
|
});
|
||||||
|
@ -461,7 +464,7 @@ async fn test_client_gzip_encoding_large() {
|
||||||
let data = e.finish().unwrap();
|
let data = e.finish().unwrap();
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.header("content-encoding", "gzip")
|
.insert_header(("content-encoding", "gzip"))
|
||||||
.body(data)
|
.body(data)
|
||||||
})))
|
})))
|
||||||
});
|
});
|
||||||
|
@ -489,7 +492,7 @@ async fn test_client_gzip_encoding_large_random() {
|
||||||
e.write_all(&data).unwrap();
|
e.write_all(&data).unwrap();
|
||||||
let data = e.finish().unwrap();
|
let data = e.finish().unwrap();
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.header("content-encoding", "gzip")
|
.insert_header(("content-encoding", "gzip"))
|
||||||
.body(data)
|
.body(data)
|
||||||
})))
|
})))
|
||||||
});
|
});
|
||||||
|
@ -511,7 +514,7 @@ async fn test_client_brotli_encoding() {
|
||||||
e.write_all(&data).unwrap();
|
e.write_all(&data).unwrap();
|
||||||
let data = e.finish().unwrap();
|
let data = e.finish().unwrap();
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.header("content-encoding", "br")
|
.insert_header(("content-encoding", "br"))
|
||||||
.body(data)
|
.body(data)
|
||||||
})))
|
})))
|
||||||
});
|
});
|
||||||
|
@ -539,7 +542,7 @@ async fn test_client_brotli_encoding_large_random() {
|
||||||
e.write_all(&data).unwrap();
|
e.write_all(&data).unwrap();
|
||||||
let data = e.finish().unwrap();
|
let data = e.finish().unwrap();
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.header("content-encoding", "br")
|
.insert_header(("content-encoding", "br"))
|
||||||
.body(data)
|
.body(data)
|
||||||
})))
|
})))
|
||||||
});
|
});
|
||||||
|
|
|
@ -211,7 +211,7 @@ pub mod client {
|
||||||
//!
|
//!
|
||||||
//! // Create request builder and send request
|
//! // Create request builder and send request
|
||||||
//! let response = client.get("http://www.rust-lang.org")
|
//! let response = client.get("http://www.rust-lang.org")
|
||||||
//! .header("User-Agent", "actix-web/3.0")
|
//! .insert_header(("User-Agent", "actix-web/3.0"))
|
||||||
//! .send() // <- Send request
|
//! .send() // <- Send request
|
||||||
//! .await; // <- Wait for response
|
//! .await; // <- Wait for response
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -439,8 +439,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_request_cookies() {
|
fn test_request_cookies() {
|
||||||
let req = TestRequest::default()
|
let req = TestRequest::default()
|
||||||
.insert_header((header::COOKIE, "cookie1=value1"))
|
.append_header((header::COOKIE, "cookie1=value1"))
|
||||||
.insert_header((header::COOKIE, "cookie2=value2"))
|
.append_header((header::COOKIE, "cookie2=value2"))
|
||||||
.to_http_request();
|
.to_http_request();
|
||||||
{
|
{
|
||||||
let cookies = req.cookies().unwrap();
|
let cookies = req.cookies().unwrap();
|
||||||
|
|
|
@ -446,7 +446,7 @@ impl TestRequest {
|
||||||
where
|
where
|
||||||
H: IntoHeaderPair,
|
H: IntoHeaderPair,
|
||||||
{
|
{
|
||||||
self.req.insert_header(header);
|
self.req.append_header(header);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue