fix doctests

This commit is contained in:
Rob Ede 2021-01-11 04:24:58 +00:00
parent 698737950a
commit e68f589ccd
No known key found for this signature in database
GPG Key ID: C2A3B36E841A91E6
36 changed files with 314 additions and 329 deletions

View File

@ -101,7 +101,7 @@ mod tests {
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
let req = TestRequest::default()
.header(header::IF_MODIFIED_SINCE, since)
.insert_header((header::IF_MODIFIED_SINCE, since))
.to_http_request();
let resp = file.respond_to(&req).await.unwrap();
assert_eq!(resp.status(), StatusCode::NOT_MODIFIED);
@ -126,8 +126,8 @@ mod tests {
header::HttpDate::from(SystemTime::now().add(Duration::from_secs(60)));
let req = TestRequest::default()
.header(header::IF_NONE_MATCH, "miss_etag")
.header(header::IF_MODIFIED_SINCE, since)
.insert_header((header::IF_NONE_MATCH, "miss_etag"))
.insert_header((header::IF_MODIFIED_SINCE, since))
.to_http_request();
let resp = file.respond_to(&req).await.unwrap();
assert_ne!(resp.status(), StatusCode::NOT_MODIFIED);
@ -398,7 +398,7 @@ mod tests {
// Valid range header
let request = TestRequest::get()
.uri("/t%65st/Cargo.toml")
.header(header::RANGE, "bytes=10-20")
.insert_header((header::RANGE, "bytes=10-20"))
.to_request();
let response = test::call_service(&mut srv, request).await;
assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);
@ -406,7 +406,7 @@ mod tests {
// Invalid range header
let request = TestRequest::get()
.uri("/t%65st/Cargo.toml")
.header(header::RANGE, "bytes=1-0")
.insert_header((header::RANGE, "bytes=1-0"))
.to_request();
let response = test::call_service(&mut srv, request).await;
@ -420,7 +420,7 @@ mod tests {
// Valid range header
let response = srv
.get("/tests/test.binary")
.header(header::RANGE, "bytes=10-20")
.insert_header((header::RANGE, "bytes=10-20"))
.send()
.await
.unwrap();
@ -430,7 +430,7 @@ mod tests {
// Invalid range header
let response = srv
.get("/tests/test.binary")
.header(header::RANGE, "bytes=10-5")
.insert_header((header::RANGE, "bytes=10-5"))
.send()
.await
.unwrap();
@ -445,7 +445,7 @@ mod tests {
// Valid range header
let response = srv
.get("/tests/test.binary")
.header(header::RANGE, "bytes=10-20")
.insert_header((header::RANGE, "bytes=10-20"))
.send()
.await
.unwrap();
@ -455,7 +455,7 @@ mod tests {
// Valid range header, starting from 0
let response = srv
.get("/tests/test.binary")
.header(header::RANGE, "bytes=0-20")
.insert_header((header::RANGE, "bytes=0-20"))
.send()
.await
.unwrap();
@ -560,7 +560,7 @@ mod tests {
let request = TestRequest::get()
.uri("/")
.header(header::ACCEPT_ENCODING, "gzip")
.insert_header((header::ACCEPT_ENCODING, "gzip"))
.to_request();
let res = test::call_service(&mut srv, request).await;
assert_eq!(res.status(), StatusCode::OK);
@ -580,7 +580,7 @@ mod tests {
let request = TestRequest::get()
.uri("/")
.header(header::ACCEPT_ENCODING, "gzip")
.insert_header((header::ACCEPT_ENCODING, "gzip"))
.to_request();
let res = test::call_service(&mut srv, request).await;
assert_eq!(res.status(), StatusCode::OK);

View File

@ -282,16 +282,16 @@ impl NamedFile {
if self.flags.contains(Flags::PREFER_UTF8) {
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 {
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) {
res.header(
res.insert_header((
header::CONTENT_DISPOSITION,
self.content_disposition.to_string(),
);
));
}
if let Some(current_encoding) = self.encoding {
@ -361,16 +361,16 @@ impl NamedFile {
if self.flags.contains(Flags::PREFER_UTF8) {
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 {
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) {
resp.header(
resp.insert_header((
header::CONTENT_DISPOSITION,
self.content_disposition.to_string(),
);
));
}
// default compressing
@ -379,14 +379,14 @@ impl NamedFile {
}
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 {
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 offset = 0;
@ -399,7 +399,7 @@ impl NamedFile {
offset = ranges[0].start;
resp.encoding(ContentEncoding::Identity);
resp.header(
resp.insert_header((
header::CONTENT_RANGE,
format!(
"bytes {}-{}/{}",
@ -407,9 +407,12 @@ impl NamedFile {
offset + length - 1,
self.md.len()
),
);
));
} 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();
};
} else {

View File

@ -78,7 +78,7 @@ impl Service<ServiceRequest> for FilesService {
if !is_method_valid {
return Either::Left(ok(req.into_response(
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."),
)));
}
@ -102,7 +102,7 @@ impl Service<ServiceRequest> for FilesService {
return Either::Left(ok(req.into_response(
HttpResponse::Found()
.header(header::LOCATION, redirect_to)
.insert_header((header::LOCATION, redirect_to))
.body("")
.into_body(),
)));

View File

@ -26,7 +26,10 @@ async fn main() -> io::Result<()> {
info!("request body: {:?}", body);
Ok::<_, Error>(
Response::Ok()
.header("x-head", HeaderValue::from_static("dummy value!"))
.insert_header((
"x-head",
HeaderValue::from_static("dummy value!"),
))
.body(body),
)
})

View File

@ -15,7 +15,7 @@ async fn handle_request(mut req: Request) -> Result<Response, Error> {
info!("request body: {:?}", body);
Ok(Response::Ok()
.header("x-head", HeaderValue::from_static("dummy value!"))
.insert_header(("x-head", HeaderValue::from_static("dummy value!")))
.body(body))
}

View File

@ -19,7 +19,10 @@ async fn main() -> io::Result<()> {
.finish(|_req| {
info!("{:?}", _req);
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!"))
})
.tcp()

View File

@ -32,50 +32,36 @@ header! {
/// * `text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c`
///
/// # Examples
/// ```rust
/// # extern crate actix_http;
/// extern crate mime;
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{Accept, qitem};
///
/// # fn main() {
/// let mut builder = Response::Ok();
///
/// builder.set(
/// builder.insert_header(
/// Accept(vec![
/// qitem(mime::TEXT_HTML),
/// ])
/// );
/// # }
/// ```
///
/// ```rust
/// # extern crate actix_http;
/// extern crate mime;
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{Accept, qitem};
///
/// # fn main() {
/// let mut builder = Response::Ok();
///
/// builder.set(
/// builder.insert_header(
/// Accept(vec![
/// qitem(mime::APPLICATION_JSON),
/// ])
/// );
/// # }
/// ```
///
/// ```rust
/// # extern crate actix_http;
/// extern crate mime;
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{Accept, QualityItem, q, qitem};
///
/// # fn main() {
/// let mut builder = Response::Ok();
///
/// builder.set(
/// builder.insert_header(
/// Accept(vec![
/// qitem(mime::TEXT_HTML),
/// qitem("application/xhtml+xml".parse().unwrap()),
@ -90,7 +76,6 @@ header! {
/// ),
/// ])
/// );
/// # }
/// ```
(Accept, header::ACCEPT) => (QualityItem<Mime>)+
@ -132,7 +117,7 @@ header! {
#[test]
fn test_fuzzing1() {
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);
assert!(header.is_ok());
}

View File

@ -21,44 +21,37 @@ header! {
/// * `iso-8859-5, unicode-1-1;q=0.8`
///
/// # Examples
/// ```rust
/// # extern crate actix_http;
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{AcceptCharset, Charset, qitem};
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// AcceptCharset(vec![qitem(Charset::Us_Ascii)])
/// );
/// # }
/// ```
/// ```rust
/// # extern crate actix_http;
///
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{AcceptCharset, Charset, q, QualityItem};
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// AcceptCharset(vec![
/// QualityItem::new(Charset::Us_Ascii, q(900)),
/// QualityItem::new(Charset::Iso_8859_10, q(200)),
/// ])
/// );
/// # }
/// ```
/// ```rust
/// # extern crate actix_http;
///
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{AcceptCharset, Charset, qitem};
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// AcceptCharset(vec![qitem(Charset::Ext("utf-8".to_owned()))])
/// );
/// # }
/// ```
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+

View File

@ -22,41 +22,35 @@ header! {
///
/// # Examples
///
/// ```rust
/// # extern crate actix_http;
/// # extern crate language_tags;
/// ```
/// use language_tags::langtag;
/// use actix_http::Response;
/// use actix_http::http::header::{AcceptLanguage, LanguageTag, qitem};
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// let mut langtag: LanguageTag = Default::default();
/// langtag.language = Some("en".to_owned());
/// langtag.region = Some("US".to_owned());
/// builder.set(
/// builder.insert_header(
/// AcceptLanguage(vec![
/// qitem(langtag),
/// ])
/// );
/// # }
/// ```
///
/// ```rust
/// # extern crate actix_http;
/// # #[macro_use] extern crate language_tags;
/// ```
/// use language_tags::langtag;
/// use actix_http::Response;
/// use actix_http::http::header::{AcceptLanguage, QualityItem, q, qitem};
/// #
/// # fn main() {
///
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// AcceptLanguage(vec![
/// qitem(langtag!(da)),
/// QualityItem::new(langtag!(en;;;GB), q(800)),
/// QualityItem::new(langtag!(en), q(700)),
/// ])
/// );
/// # }
/// ```
(AcceptLanguage, ACCEPT_LANGUAGE) => (QualityItem<LanguageTag>)+

View File

@ -22,38 +22,28 @@ header! {
///
/// # Examples
///
/// ```rust
/// # extern crate http;
/// # extern crate actix_http;
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::Allow;
/// use http::Method;
/// use actix_http::http::{header::Allow, Method};
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// Allow(vec![Method::GET])
/// );
/// # }
/// ```
///
/// ```rust
/// # extern crate http;
/// # extern crate actix_http;
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::Allow;
/// use http::Method;
/// use actix_http::http::{header::Allow, Method};
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// Allow(vec![
/// Method::GET,
/// Method::POST,
/// Method::PATCH,
/// ])
/// );
/// # }
/// ```
(Allow, header::ALLOW) => (Method)*

View File

@ -28,12 +28,12 @@ use crate::header::{
/// * `max-age=30`
///
/// # Examples
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{CacheControl, CacheDirective};
///
/// let mut builder = Response::Ok();
/// builder.set(CacheControl(vec![CacheDirective::MaxAge(86400u32)]));
/// builder.insert_header(CacheControl(vec![CacheDirective::MaxAge(86400u32)]));
/// ```
///
/// ```rust
@ -41,7 +41,7 @@ use crate::header::{
/// use actix_http::http::header::{CacheControl, CacheDirective};
///
/// let mut builder = Response::Ok();
/// builder.set(CacheControl(vec![
/// builder.insert_header(CacheControl(vec![
/// CacheDirective::NoCache,
/// CacheDirective::Private,
/// CacheDirective::MaxAge(360u32),
@ -196,7 +196,8 @@ mod tests {
#[test]
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();
let cache = Header::parse(&req);
assert_eq!(
@ -210,9 +211,9 @@ mod tests {
#[test]
fn test_parse_argument() {
let req =
TestRequest::default().insert_header(header::CACHE_CONTROL, "max-age=100, private")
.finish();
let req = TestRequest::default()
.insert_header((header::CACHE_CONTROL, "max-age=100, private"))
.finish();
let cache = Header::parse(&req);
assert_eq!(
cache.ok(),
@ -225,8 +226,9 @@ mod tests {
#[test]
fn test_parse_quote_form() {
let req =
TestRequest::default().insert_header(header::CACHE_CONTROL, "max-age=\"200\"").finish();
let req = TestRequest::default()
.insert_header((header::CACHE_CONTROL, "max-age=\"200\""))
.finish();
let cache = Header::parse(&req);
assert_eq!(
cache.ok(),
@ -236,8 +238,9 @@ mod tests {
#[test]
fn test_parse_extension() {
let req =
TestRequest::default().insert_header(header::CACHE_CONTROL, "foo, bar=baz").finish();
let req = TestRequest::default()
.insert_header((header::CACHE_CONTROL, "foo, bar=baz"))
.finish();
let cache = Header::parse(&req);
assert_eq!(
cache.ok(),
@ -250,7 +253,9 @@ mod tests {
#[test]
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);
assert_eq!(cache.ok(), None)
}

View File

@ -23,38 +23,31 @@ header! {
///
/// # Examples
///
/// ```rust
/// # extern crate actix_http;
/// # #[macro_use] extern crate language_tags;
/// ```
/// use language_tags::langtag;
/// use actix_http::Response;
/// # use actix_http::http::header::{ContentLanguage, qitem};
/// #
/// # fn main() {
/// use actix_http::http::header::{ContentLanguage, qitem};
///
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// ContentLanguage(vec![
/// qitem(langtag!(en)),
/// ])
/// );
/// # }
/// ```
///
/// ```rust
/// # extern crate actix_http;
/// # #[macro_use] extern crate language_tags;
/// ```
/// use language_tags::langtag;
/// use actix_http::Response;
/// # use actix_http::http::header::{ContentLanguage, qitem};
/// #
/// # fn main() {
/// use actix_http::http::header::{ContentLanguage, qitem};
///
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// ContentLanguage(vec![
/// qitem(langtag!(da)),
/// qitem(langtag!(en;;;GB)),
/// ])
/// );
/// # }
/// ```
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+

View File

@ -30,31 +30,24 @@ header! {
///
/// # Examples
///
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::ContentType;
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// ContentType::json()
/// );
/// # }
/// ```
///
/// ```rust
/// # extern crate mime;
/// # extern crate actix_http;
/// use mime::TEXT_HTML;
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::ContentType;
///
/// # fn main() {
/// let mut builder = Response::Ok();
/// builder.set(
/// ContentType(TEXT_HTML)
/// builder.insert_header(
/// ContentType(mime::TEXT_HTML)
/// );
/// # }
/// ```
(ContentType, CONTENT_TYPE) => [Mime]

View File

@ -19,13 +19,15 @@ header! {
///
/// # Example
///
/// ```rust
/// ```
/// use std::time::SystemTime;
/// use actix_http::Response;
/// use actix_http::http::header::Date;
/// use std::time::SystemTime;
///
/// let mut builder = Response::Ok();
/// builder.set(Date(SystemTime::now().into()));
/// builder.insert_header(
/// Date(SystemTime::now().into())
/// );
/// ```
(Date, DATE) => [HttpDate]

View File

@ -27,20 +27,24 @@ header! {
///
/// # Examples
///
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{ETag, EntityTag};
///
/// 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::http::header::{ETag, EntityTag};
///
/// 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]

View File

@ -21,14 +21,16 @@ header! {
///
/// # Example
///
/// ```rust
/// ```
/// use std::time::{SystemTime, Duration};
/// use actix_http::Response;
/// use actix_http::http::header::Expires;
/// use std::time::{SystemTime, Duration};
///
/// let mut builder = Response::Ok();
/// let expiration = SystemTime::now() + Duration::from_secs(60 * 60 * 24);
/// builder.set(Expires(expiration.into()));
/// builder.insert_header(
/// Expires(expiration.into())
/// );
/// ```
(Expires, EXPIRES) => [HttpDate]

View File

@ -29,20 +29,20 @@ header! {
///
/// # Examples
///
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::IfMatch;
///
/// let mut builder = Response::Ok();
/// builder.set(IfMatch::Any);
/// builder.insert_header(IfMatch::Any);
/// ```
///
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{IfMatch, EntityTag};
///
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// IfMatch::Items(vec![
/// EntityTag::new(false, "xyzzy".to_owned()),
/// EntityTag::new(false, "foobar".to_owned()),

View File

@ -21,14 +21,16 @@ header! {
///
/// # Example
///
/// ```rust
/// ```
/// use std::time::{SystemTime, Duration};
/// use actix_http::Response;
/// use actix_http::http::header::IfModifiedSince;
/// use std::time::{SystemTime, Duration};
///
/// let mut builder = Response::Ok();
/// 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]

View File

@ -31,20 +31,20 @@ header! {
///
/// # Examples
///
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::IfNoneMatch;
///
/// let mut builder = Response::Ok();
/// builder.set(IfNoneMatch::Any);
/// builder.insert_header(IfNoneMatch::Any);
/// ```
///
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{IfNoneMatch, EntityTag};
///
/// let mut builder = Response::Ok();
/// builder.set(
/// builder.insert_header(
/// IfNoneMatch::Items(vec![
/// EntityTag::new(false, "xyzzy".to_owned()),
/// EntityTag::new(false, "foobar".to_owned()),
@ -73,13 +73,15 @@ mod tests {
fn test_if_none_match() {
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);
assert_eq!(if_none_match.ok(), Some(IfNoneMatch::Any));
let req =
TestRequest::default().insert_header(IF_NONE_MATCH, &b"\"foobar\", W/\"weak-etag\""[..])
.finish();
let req = TestRequest::default()
.insert_header((IF_NONE_MATCH, &b"\"foobar\", W/\"weak-etag\""[..]))
.finish();
if_none_match = Header::parse(&req);
let mut entities: Vec<EntityTag> = Vec::new();

View File

@ -35,24 +35,27 @@ use crate::httpmessage::HttpMessage;
///
/// # Examples
///
/// ```rust
/// ```
/// use actix_http::Response;
/// use actix_http::http::header::{EntityTag, IfRange};
///
/// let mut builder = Response::Ok();
/// builder.set(IfRange::EntityTag(EntityTag::new(
/// false,
/// "abc".to_owned(),
/// )));
/// builder.insert_header(
/// IfRange::EntityTag(
/// EntityTag::new(false, "abc".to_owned())
/// )
/// );
/// ```
///
/// ```rust
/// ```
/// use std::time::{Duration, SystemTime};
/// use actix_http::{http::header::IfRange, Response};
///
/// let mut builder = Response::Ok();
/// 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)]
pub enum IfRange {

View File

@ -22,14 +22,16 @@ header! {
///
/// # Example
///
/// ```rust
/// ```
/// use std::time::{SystemTime, Duration};
/// use actix_http::Response;
/// use actix_http::http::header::IfUnmodifiedSince;
/// use std::time::{SystemTime, Duration};
///
/// let mut builder = Response::Ok();
/// 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]

View File

@ -21,14 +21,16 @@ header! {
///
/// # Example
///
/// ```rust
/// ```
/// use std::time::{SystemTime, Duration};
/// use actix_http::Response;
/// use actix_http::http::header::LastModified;
/// use std::time::{SystemTime, Duration};
///
/// let mut builder = Response::Ok();
/// 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]

View File

@ -84,7 +84,7 @@ macro_rules! test_header {
let a: Vec<Vec<u8>> = raw.iter().map(|x| x.to_vec()).collect();
let mut req = test::TestRequest::default();
for item in a {
req = req.header(HeaderField::name(), item).take();
req = req.insert_header((HeaderField::name(), item)).take();
}
let req = req.finish();
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 mut req = test::TestRequest::default();
for item in a {
req.header(HeaderField::name(), item);
req.insert_header((HeaderField::name(), item));
}
let req = req.finish();
let val = HeaderField::parse(&req);
@ -334,7 +334,7 @@ macro_rules! header {
}
mod accept_charset;
//mod accept_encoding;
// mod accept_encoding;
mod accept;
mod accept_language;
mod allow;

View File

@ -174,11 +174,11 @@ mod tests {
#[test]
fn test_content_type() {
let req = TestRequest::default()
.insert_header("content-type", "text/plain")
.insert_header(("content-type", "text/plain"))
.finish();
assert_eq!(req.content_type(), "text/plain");
let req = TestRequest::default()
.insert_header("content-type", "application/json; charset=utf=8")
.insert_header(("content-type", "application/json; charset=utf=8"))
.finish();
assert_eq!(req.content_type(), "application/json");
let req = TestRequest::default().finish();
@ -188,13 +188,13 @@ mod tests {
#[test]
fn test_mime_type() {
let req = TestRequest::default()
.insert_header("content-type", "application/json")
.insert_header(("content-type", "application/json"))
.finish();
assert_eq!(req.mime_type().unwrap(), Some(mime::APPLICATION_JSON));
let req = TestRequest::default().finish();
assert_eq!(req.mime_type().unwrap(), None);
let req = TestRequest::default()
.insert_header("content-type", "application/json; charset=utf-8")
.insert_header(("content-type", "application/json; charset=utf-8"))
.finish();
let mt = req.mime_type().unwrap().unwrap();
assert_eq!(mt.get_param(mime::CHARSET), Some(mime::UTF_8));
@ -205,7 +205,7 @@ mod tests {
#[test]
fn test_mime_type_error() {
let req = TestRequest::default()
.insert_header("content-type", "applicationadfadsfasdflknadsfklnadsfjson")
.insert_header(("content-type", "applicationadfadsfasdflknadsfklnadsfjson"))
.finish();
assert_eq!(Err(ContentTypeError::ParseError), req.mime_type());
}
@ -216,12 +216,12 @@ mod tests {
assert_eq!(UTF_8.name(), req.encoding().unwrap().name());
let req = TestRequest::default()
.insert_header("content-type", "application/json")
.insert_header(("content-type", "application/json"))
.finish();
assert_eq!(UTF_8.name(), req.encoding().unwrap().name());
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();
assert_eq!(ISO_8859_2, req.encoding().unwrap());
}
@ -229,12 +229,12 @@ mod tests {
#[test]
fn test_encoding_error() {
let req = TestRequest::default()
.insert_header("content-type", "applicatjson")
.insert_header(("content-type", "applicatjson"))
.finish();
assert_eq!(Some(ContentTypeError::ParseError), req.encoding().err());
let req = TestRequest::default()
.insert_header("content-type", "application/json; charset=kkkttktk")
.insert_header(("content-type", "application/json; charset=kkkttktk"))
.finish();
assert_eq!(
Some(ContentTypeError::UnknownEncoding),
@ -248,15 +248,15 @@ mod tests {
assert!(!req.chunked().unwrap());
let req = TestRequest::default()
.insert_header(header::TRANSFER_ENCODING, "chunked")
.insert_header((header::TRANSFER_ENCODING, "chunked"))
.finish();
assert!(req.chunked().unwrap());
let req = TestRequest::default()
.header(
.insert_header((
header::TRANSFER_ENCODING,
Bytes::from_static(b"some va\xadscc\xacas0xsdasdlue"),
)
))
.finish();
assert!(req.chunked().is_err());
}

View File

@ -348,10 +348,12 @@ impl ResponseBuilder {
///
/// ```rust
/// # use actix_http::Response;
///
/// use actix_http::http::header::ContentType;
/// Response::Ok()
/// .set_header(("X-TEST", "value"))
/// .set_header(ContentType(mime::APPLICATION_JSON))
/// .finish()
/// .insert_header(("X-TEST", "value"))
/// .insert_header(ContentType(mime::APPLICATION_JSON))
/// .finish();
/// ```
pub fn insert_header<H>(&mut self, header: H) -> &mut Self
where
@ -371,10 +373,12 @@ impl ResponseBuilder {
///
/// ```rust
/// # use actix_http::Response;
/// use actix_http::http::header::ContentType;
///
/// Response::Ok()
/// .append_header(("X-TEST", "value"))
/// .append_header(ContentType(mime::APPLICATION_JSON))
/// .finish()
/// .finish();
/// ```
pub fn append_header<H>(&mut self, header: H) -> &mut Self
where
@ -822,8 +826,8 @@ mod tests {
#[test]
fn test_debug() {
let resp = Response::Ok()
.header(COOKIE, HeaderValue::from_static("cookie1=value1; "))
.header(COOKIE, HeaderValue::from_static("cookie2=value2; "))
.append_header((COOKIE, HeaderValue::from_static("cookie1=value1; ")))
.append_header((COOKIE, HeaderValue::from_static("cookie2=value2; ")))
.finish();
let dbg = format!("{:?}", resp);
assert!(dbg.contains("Response"));
@ -834,8 +838,8 @@ mod tests {
use crate::httpmessage::HttpMessage;
let req = crate::test::TestRequest::default()
.header(COOKIE, "cookie1=value1")
.header(COOKIE, "cookie2=value2")
.append_header((COOKIE, "cookie1=value1"))
.append_header((COOKIE, "cookie2=value2"))
.finish();
let cookies = req.cookies().unwrap();
@ -889,7 +893,7 @@ mod tests {
#[test]
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);
}
@ -930,7 +934,7 @@ mod tests {
#[test]
fn test_json_ct() {
let resp = Response::build(StatusCode::OK)
.header(CONTENT_TYPE, "text/json")
.insert_header((CONTENT_TYPE, "text/json"))
.json(vec!["v1", "v2", "v3"]);
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
assert_eq!(ct, HeaderValue::from_static("text/json"));
@ -948,7 +952,7 @@ mod tests {
#[test]
fn test_json2_ct() {
let resp = Response::build(StatusCode::OK)
.header(CONTENT_TYPE, "text/json")
.insert_header((CONTENT_TYPE, "text/json"))
.json2(&vec!["v1", "v2", "v3"]);
let ct = resp.headers().get(CONTENT_TYPE).unwrap();
assert_eq!(ct, HeaderValue::from_static("text/json"));

View File

@ -224,7 +224,7 @@ mod tests {
);
let req = TestRequest::default()
.header(header::UPGRADE, header::HeaderValue::from_static("test"))
.insert_header((header::UPGRADE, header::HeaderValue::from_static("test")))
.finish();
assert_eq!(
HandshakeError::NoWebsocketUpgrade,
@ -232,10 +232,10 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
))
.finish();
assert_eq!(
HandshakeError::NoConnectionUpgrade,
@ -243,14 +243,14 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
))
.finish();
assert_eq!(
HandshakeError::NoVersionHeader,
@ -258,18 +258,18 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("5"),
)
))
.finish();
assert_eq!(
HandshakeError::UnsupportedVersion,
@ -277,18 +277,18 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("13"),
)
))
.finish();
assert_eq!(
HandshakeError::BadWebsocketKey,
@ -296,22 +296,22 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_KEY,
header::HeaderValue::from_static("13"),
)
))
.finish();
assert_eq!(
StatusCode::SWITCHING_PROTOCOLS,

View File

@ -38,7 +38,7 @@ async fn test_h1_v2() {
let response = srv.get("/").send().await.unwrap();
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();
assert!(response.status().is_success());

View File

@ -173,8 +173,8 @@ async fn test_h2_headers() {
HttpService::build().h2(move |_| {
let mut builder = Response::Ok();
for idx in 0..90 {
builder.header(
format!("X-TEST-{}", idx).as_str(),
builder.insert_header(
(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 \
@ -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 ",
);
));
}
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())));
ok::<_, ()>(
Response::Ok()
.header(header::TRANSFER_ENCODING, "chunked")
.insert_header((header::TRANSFER_ENCODING, "chunked"))
.streaming(body),
)
})
@ -369,7 +369,7 @@ async fn test_h2_response_http_error_handling() {
let broken_header = Bytes::from_static(b"\0\0\0");
ok::<_, ()>(
Response::Ok()
.header(header::CONTENT_TYPE, broken_header)
.insert_header((header::CONTENT_TYPE, broken_header))
.body(STR),
)
}))

View File

@ -392,7 +392,7 @@ async fn test_h1_headers() {
HttpService::build().h1(move |_| {
let mut builder = Response::Ok();
for idx in 0..90 {
builder.header(
builder.insert_header((
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 \
@ -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 ",
);
));
}
future::ok::<_, ()>(builder.body(data.clone()))
}).tcp()
@ -561,7 +561,7 @@ async fn test_h1_body_chunked_explicit() {
let body = once(ok::<_, Error>(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(
Response::Ok()
.header(header::TRANSFER_ENCODING, "chunked")
.insert_header((header::TRANSFER_ENCODING, "chunked"))
.streaming(body),
)
})
@ -625,7 +625,7 @@ async fn test_h1_response_http_error_handling() {
let broken_header = Bytes::from_static(b"\0\0\0");
ok::<_, ()>(
Response::Ok()
.header(http::header::CONTENT_TYPE, broken_header)
.insert_header((http::header::CONTENT_TYPE, broken_header))
.body(STR),
)
}))

View File

@ -166,11 +166,11 @@ pub fn handshake_with_protocols(
let mut response = HttpResponse::build(StatusCode::SWITCHING_PROTOCOLS)
.upgrade("websocket")
.header(header::SEC_WEBSOCKET_ACCEPT, key.as_str())
.insert_header((header::SEC_WEBSOCKET_ACCEPT, key))
.take();
if let Some(protocol) = protocol {
response.header(&header::SEC_WEBSOCKET_PROTOCOL, protocol);
response.insert_header((header::SEC_WEBSOCKET_PROTOCOL, protocol));
}
Ok(response)
@ -573,7 +573,7 @@ mod tests {
);
let req = TestRequest::default()
.header(header::UPGRADE, header::HeaderValue::from_static("test"))
.insert_header((header::UPGRADE, header::HeaderValue::from_static("test")))
.to_http_request();
assert_eq!(
HandshakeError::NoWebsocketUpgrade,
@ -581,10 +581,10 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
))
.to_http_request();
assert_eq!(
HandshakeError::NoConnectionUpgrade,
@ -592,14 +592,14 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
))
.to_http_request();
assert_eq!(
HandshakeError::NoVersionHeader,
@ -607,18 +607,18 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("5"),
)
))
.to_http_request();
assert_eq!(
HandshakeError::UnsupportedVersion,
@ -626,18 +626,18 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("13"),
)
))
.to_http_request();
assert_eq!(
HandshakeError::BadWebsocketKey,
@ -645,22 +645,22 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_KEY,
header::HeaderValue::from_static("13"),
)
))
.to_http_request();
let resp = handshake(&req).unwrap().finish();
@ -669,26 +669,26 @@ mod tests {
assert_eq!(None, resp.headers().get(&header::TRANSFER_ENCODING));
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_KEY,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_PROTOCOL,
header::HeaderValue::from_static("graphql"),
)
))
.to_http_request();
let protocols = ["graphql"];
@ -710,26 +710,26 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_KEY,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_PROTOCOL,
header::HeaderValue::from_static("p1, p2, p3"),
)
))
.to_http_request();
let protocols = vec!["p3", "p2"];
@ -751,26 +751,26 @@ mod tests {
);
let req = TestRequest::default()
.header(
.insert_header((
header::UPGRADE,
header::HeaderValue::from_static("websocket"),
)
.header(
))
.insert_header((
header::CONNECTION,
header::HeaderValue::from_static("upgrade"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_VERSION,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_KEY,
header::HeaderValue::from_static("13"),
)
.header(
))
.insert_header((
header::SEC_WEBSOCKET_PROTOCOL,
header::HeaderValue::from_static("p1,p2,p3"),
)
))
.to_http_request();
let protocols = vec!["p3", "p2"];

View File

@ -7,7 +7,7 @@
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
//! let mut client = awc::Client::default();
//! 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
//! .await?;
//!
@ -134,7 +134,7 @@ use self::connect::{Connect, ConnectorWrapper};
/// let mut client = Client::default();
///
/// 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
/// .await; // <- send request and wait for response
///

View File

@ -37,13 +37,11 @@ cfg_if::cfg_if! {
/// builder-like pattern.
///
/// ```rust
/// use actix_rt::System;
///
/// #[actix_rt::main]
/// async fn main() {
/// let response = awc::Client::new()
/// .get("http://www.rust-lang.org") // <- Create request builder
/// .header("User-Agent", "Actix-web")
/// .insert_header(("User-Agent", "Actix-web"))
/// .send() // <- Send http request
/// .await;
///
@ -188,17 +186,16 @@ impl ClientRequest {
/// Append a header, keeping any that were set with an equivalent field name.
///
/// ```rust
/// use awc::{http, Client};
/// # #[actix_rt::main]
/// # async fn main() {
/// # use awc::Client;
/// use awc::http::header::ContentType;
///
/// fn main() {
/// # actix_rt::System::new("test").block_on(async {
/// let req = Client::new()
/// .get("http://www.rust-lang.org")
/// .header("X-TEST", "value")
/// .header(http::header::CONTENT_TYPE, "application/json");
/// # Ok::<_, ()>(())
/// # });
/// }
/// Client::new()
/// .get("http://www.rust-lang.org")
/// .insert_header(("X-TEST", "value"))
/// .insert_header(ContentType(mime::APPLICATION_JSON));
/// # }
/// ```
pub fn append_header<H>(mut self, header: H) -> Self
where
@ -560,7 +557,7 @@ mod tests {
#[actix_rt::test]
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);
assert!(repr.contains("ClientRequest"));
assert!(repr.contains("x-test"));
@ -571,18 +568,18 @@ mod tests {
let req = Client::new()
.put("/")
.version(Version::HTTP_2)
.set(header::Date(SystemTime::now().into()))
.insert_header(header::Date(SystemTime::now().into()))
.content_type("plain/text")
.append_header(header::SERVER, "awc");
.append_header((header::SERVER, "awc"));
let req = if let Some(val) = Some("server") {
req.append_header(header::USER_AGENT, val)
req.append_header((header::USER_AGENT, val))
} else {
req
};
let req = if let Some(_val) = Option::<&str>::None {
req.append_header(header::ALLOW, "1")
req.append_header((header::ALLOW, "1"))
} else {
req
};
@ -625,7 +622,7 @@ mod tests {
.header(header::CONTENT_TYPE, "111")
.finish()
.get("/")
.insert_header(header::CONTENT_TYPE, "222");
.insert_header((header::CONTENT_TYPE, "222"));
assert_eq!(
req.head

View File

@ -52,7 +52,7 @@ async fn test_simple() {
.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();
assert!(response.status().is_success());
@ -82,7 +82,7 @@ async fn test_json() {
let request = srv
.get("/")
.append_header("x-test", "111")
.insert_header(("x-test", "111"))
.send_json(&"TEST".to_string());
let response = request.await.unwrap();
assert!(response.status().is_success());
@ -99,7 +99,10 @@ async fn test_form() {
let mut data = HashMap::new();
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();
assert!(response.status().is_success());
}
@ -438,7 +441,7 @@ async fn test_client_gzip_encoding() {
let data = e.finish().unwrap();
HttpResponse::Ok()
.header("content-encoding", "gzip")
.insert_header(("content-encoding", "gzip"))
.body(data)
})))
});
@ -461,7 +464,7 @@ async fn test_client_gzip_encoding_large() {
let data = e.finish().unwrap();
HttpResponse::Ok()
.header("content-encoding", "gzip")
.insert_header(("content-encoding", "gzip"))
.body(data)
})))
});
@ -489,7 +492,7 @@ async fn test_client_gzip_encoding_large_random() {
e.write_all(&data).unwrap();
let data = e.finish().unwrap();
HttpResponse::Ok()
.header("content-encoding", "gzip")
.insert_header(("content-encoding", "gzip"))
.body(data)
})))
});
@ -511,7 +514,7 @@ async fn test_client_brotli_encoding() {
e.write_all(&data).unwrap();
let data = e.finish().unwrap();
HttpResponse::Ok()
.header("content-encoding", "br")
.insert_header(("content-encoding", "br"))
.body(data)
})))
});
@ -539,7 +542,7 @@ async fn test_client_brotli_encoding_large_random() {
e.write_all(&data).unwrap();
let data = e.finish().unwrap();
HttpResponse::Ok()
.header("content-encoding", "br")
.insert_header(("content-encoding", "br"))
.body(data)
})))
});

View File

@ -211,7 +211,7 @@ pub mod client {
//!
//! // Create request builder and send request
//! 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
//! .await; // <- Wait for response
//!

View File

@ -439,8 +439,8 @@ mod tests {
#[test]
fn test_request_cookies() {
let req = TestRequest::default()
.insert_header((header::COOKIE, "cookie1=value1"))
.insert_header((header::COOKIE, "cookie2=value2"))
.append_header((header::COOKIE, "cookie1=value1"))
.append_header((header::COOKIE, "cookie2=value2"))
.to_http_request();
{
let cookies = req.cookies().unwrap();

View File

@ -446,7 +446,7 @@ impl TestRequest {
where
H: IntoHeaderPair,
{
self.req.insert_header(header);
self.req.append_header(header);
self
}