mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-25 18:09:22 +02:00
re-arrange modules and exports
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
use mime::{self, Mime};
|
||||
use header::{QualityItem, qitem, http};
|
||||
use header::{QualityItem, qitem};
|
||||
use http::header as http;
|
||||
|
||||
header! {
|
||||
/// `Accept` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-5.3.2)
|
||||
@ -32,7 +33,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// extern crate mime;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{Accept, qitem};
|
||||
/// use actix_web::http::header::{Accept, qitem};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -49,7 +50,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// extern crate mime;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{Accept, qitem};
|
||||
/// use actix_web::http::header::{Accept, qitem};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -66,7 +67,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// extern crate mime;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{Accept, QualityItem, q, qitem};
|
||||
/// use actix_web::http::header::{Accept, QualityItem, q, qitem};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -128,7 +129,7 @@ header! {
|
||||
#[test]
|
||||
fn test_fuzzing1() {
|
||||
use test::TestRequest;
|
||||
let req = TestRequest::with_header(http::ACCEPT, "chunk#;e").finish();
|
||||
let req = TestRequest::with_header(super::http::ACCEPT, "chunk#;e").finish();
|
||||
let header = Accept::parse(&req);
|
||||
assert!(header.is_ok());
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, Charset, QualityItem};
|
||||
use header::{ACCEPT_CHARSET, Charset, QualityItem};
|
||||
|
||||
header! {
|
||||
/// `Accept-Charset` header, defined in
|
||||
@ -24,7 +24,7 @@ header! {
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{AcceptCharset, Charset, qitem};
|
||||
/// use actix_web::http::header::{AcceptCharset, Charset, qitem};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -36,7 +36,7 @@ header! {
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{AcceptCharset, Charset, q, QualityItem};
|
||||
/// use actix_web::http::header::{AcceptCharset, Charset, q, QualityItem};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -51,7 +51,7 @@ header! {
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{AcceptCharset, Charset, qitem};
|
||||
/// use actix_web::http::header::{AcceptCharset, Charset, qitem};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -60,7 +60,7 @@ header! {
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
(AcceptCharset, http::ACCEPT_CHARSET) => (QualityItem<Charset>)+
|
||||
(AcceptCharset, ACCEPT_CHARSET) => (QualityItem<Charset>)+
|
||||
|
||||
test_accept_charset {
|
||||
/// Test case from RFC
|
||||
|
@ -1,5 +1,5 @@
|
||||
use language_tags::LanguageTag;
|
||||
use header::{http, QualityItem};
|
||||
use header::{ACCEPT_LANGUAGE, QualityItem};
|
||||
|
||||
|
||||
header! {
|
||||
@ -27,7 +27,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate language_tags;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{AcceptLanguage, LanguageTag, qitem};
|
||||
/// use actix_web::http::header::{AcceptLanguage, LanguageTag, qitem};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -46,7 +46,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// # #[macro_use] extern crate language_tags;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{AcceptLanguage, QualityItem, q, qitem};
|
||||
/// use actix_web::http::header::{AcceptLanguage, QualityItem, q, qitem};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -59,7 +59,7 @@ header! {
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
(AcceptLanguage, http::ACCEPT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
||||
(AcceptLanguage, ACCEPT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
||||
|
||||
test_accept_language {
|
||||
// From the RFC
|
||||
|
@ -1,5 +1,5 @@
|
||||
use http::Method;
|
||||
use header::http;
|
||||
use http::header;
|
||||
|
||||
header! {
|
||||
/// `Allow` header, defined in [RFC7231](http://tools.ietf.org/html/rfc7231#section-7.4.1)
|
||||
@ -26,7 +26,7 @@ header! {
|
||||
/// # extern crate http;
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::Allow;
|
||||
/// use actix_web::http::header::Allow;
|
||||
/// use http::Method;
|
||||
///
|
||||
/// # fn main() {
|
||||
@ -41,7 +41,7 @@ header! {
|
||||
/// # extern crate http;
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::Allow;
|
||||
/// use actix_web::http::header::Allow;
|
||||
/// use http::Method;
|
||||
///
|
||||
/// # fn main() {
|
||||
@ -55,7 +55,7 @@ header! {
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
(Allow, http::ALLOW) => (Method)*
|
||||
(Allow, header::ALLOW) => (Method)*
|
||||
|
||||
test_allow {
|
||||
// From the RFC
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std::fmt::{self, Write};
|
||||
use std::str::FromStr;
|
||||
use http::header;
|
||||
use header::{Header, IntoHeaderValue, Writer};
|
||||
use header::{http, from_comma_delimited, fmt_comma_delimited};
|
||||
use header::{from_comma_delimited, fmt_comma_delimited};
|
||||
|
||||
/// `Cache-Control` header, defined in [RFC7234](https://tools.ietf.org/html/rfc7234#section-5.2)
|
||||
///
|
||||
@ -26,7 +27,7 @@ use header::{http, from_comma_delimited, fmt_comma_delimited};
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{CacheControl, CacheDirective};
|
||||
/// use actix_web::http::header::{CacheControl, CacheDirective};
|
||||
///
|
||||
/// let mut builder = HttpOk.build();
|
||||
/// builder.set(
|
||||
@ -36,7 +37,7 @@ use header::{http, from_comma_delimited, fmt_comma_delimited};
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::{CacheControl, CacheDirective};
|
||||
/// use actix_web::http::header::{CacheControl, CacheDirective};
|
||||
///
|
||||
/// let mut builder = HttpOk.build();
|
||||
/// builder.set(
|
||||
@ -56,8 +57,8 @@ __hyper__deref!(CacheControl => Vec<CacheDirective>);
|
||||
|
||||
//TODO: this could just be the header! macro
|
||||
impl Header for CacheControl {
|
||||
fn name() -> http::HeaderName {
|
||||
http::CACHE_CONTROL
|
||||
fn name() -> header::HeaderName {
|
||||
header::CACHE_CONTROL
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -80,12 +81,12 @@ impl fmt::Display for CacheControl {
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for CacheControl {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = header::InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<header::HeaderValue, Self::Error> {
|
||||
let mut writer = Writer::new();
|
||||
let _ = write!(&mut writer, "{}", self);
|
||||
http::HeaderValue::from_shared(writer.take())
|
||||
header::HeaderValue::from_shared(writer.take())
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +190,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_multiple_headers() {
|
||||
let req = TestRequest::with_header(
|
||||
http::CACHE_CONTROL, "no-cache, private").finish();
|
||||
header::CACHE_CONTROL, "no-cache, private").finish();
|
||||
let cache = Header::parse(&req);
|
||||
assert_eq!(cache.ok(), Some(CacheControl(vec![CacheDirective::NoCache,
|
||||
CacheDirective::Private])))
|
||||
@ -198,7 +199,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_argument() {
|
||||
let req = TestRequest::with_header(
|
||||
http::CACHE_CONTROL, "max-age=100, private").finish();
|
||||
header::CACHE_CONTROL, "max-age=100, private").finish();
|
||||
let cache = Header::parse(&req);
|
||||
assert_eq!(cache.ok(), Some(CacheControl(vec![CacheDirective::MaxAge(100),
|
||||
CacheDirective::Private])))
|
||||
@ -207,7 +208,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_quote_form() {
|
||||
let req = TestRequest::with_header(
|
||||
http::CACHE_CONTROL, "max-age=\"200\"").finish();
|
||||
header::CACHE_CONTROL, "max-age=\"200\"").finish();
|
||||
let cache = Header::parse(&req);
|
||||
assert_eq!(cache.ok(), Some(CacheControl(vec![CacheDirective::MaxAge(200)])))
|
||||
}
|
||||
@ -215,7 +216,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_extension() {
|
||||
let req = TestRequest::with_header(
|
||||
http::CACHE_CONTROL, "foo, bar=baz").finish();
|
||||
header::CACHE_CONTROL, "foo, bar=baz").finish();
|
||||
let cache = Header::parse(&req);
|
||||
assert_eq!(cache.ok(), Some(CacheControl(vec![
|
||||
CacheDirective::Extension("foo".to_owned(), None),
|
||||
@ -224,7 +225,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_bad_syntax() {
|
||||
let req = TestRequest::with_header(http::CACHE_CONTROL, "foo=").finish();
|
||||
let req = TestRequest::with_header(header::CACHE_CONTROL, "foo=").finish();
|
||||
let cache: Result<CacheControl, _> = Header::parse(&req);
|
||||
assert_eq!(cache.ok(), None)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use language_tags::LanguageTag;
|
||||
use header::{http, QualityItem};
|
||||
use header::{CONTENT_LANGUAGE, QualityItem};
|
||||
|
||||
|
||||
header! {
|
||||
@ -28,7 +28,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// # #[macro_use] extern crate language_tags;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// # use actix_web::header::{ContentLanguage, qitem};
|
||||
/// # use actix_web::http::header::{ContentLanguage, qitem};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -44,7 +44,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// # #[macro_use] extern crate language_tags;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// # use actix_web::header::{ContentLanguage, qitem};
|
||||
/// # use actix_web::http::header::{ContentLanguage, qitem};
|
||||
/// #
|
||||
/// # fn main() {
|
||||
///
|
||||
@ -57,7 +57,7 @@ header! {
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
(ContentLanguage, http::CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
||||
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
||||
|
||||
test_content_language {
|
||||
test_header!(test1, vec![b"da"]);
|
||||
|
@ -1,13 +1,14 @@
|
||||
use std::fmt::{self, Display, Write};
|
||||
use std::str::FromStr;
|
||||
use header::{http, IntoHeaderValue, Writer};
|
||||
use error::ParseError;
|
||||
use header::{IntoHeaderValue, Writer,
|
||||
HeaderValue, InvalidHeaderValueBytes, CONTENT_RANGE};
|
||||
|
||||
|
||||
header! {
|
||||
/// `Content-Range` header, defined in
|
||||
/// [RFC7233](http://tools.ietf.org/html/rfc7233#section-4.2)
|
||||
(ContentRange, http::CONTENT_RANGE) => [ContentRangeSpec]
|
||||
(ContentRange, CONTENT_RANGE) => [ContentRangeSpec]
|
||||
|
||||
test_content_range {
|
||||
test_header!(test_bytes,
|
||||
@ -195,11 +196,11 @@ impl Display for ContentRangeSpec {
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for ContentRangeSpec {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
let mut writer = Writer::new();
|
||||
let _ = write!(&mut writer, "{}", self);
|
||||
http::HeaderValue::from_shared(writer.take())
|
||||
HeaderValue::from_shared(writer.take())
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use mime::{self, Mime};
|
||||
use header::http;
|
||||
use header::CONTENT_TYPE;
|
||||
|
||||
|
||||
header! {
|
||||
@ -33,7 +33,7 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::ContentType;
|
||||
/// use actix_web::http::header::ContentType;
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -48,7 +48,7 @@ header! {
|
||||
/// # extern crate actix_web;
|
||||
/// use mime::TEXT_HTML;
|
||||
/// use actix_web::httpcodes::HttpOk;
|
||||
/// use actix_web::header::ContentType;
|
||||
/// use actix_web::http::header::ContentType;
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let mut builder = HttpOk.build();
|
||||
@ -57,7 +57,7 @@ header! {
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
(ContentType, http::CONTENT_TYPE) => [Mime]
|
||||
(ContentType, CONTENT_TYPE) => [Mime]
|
||||
|
||||
test_content_type {
|
||||
test_header!(
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::time::SystemTime;
|
||||
use header::{http, HttpDate};
|
||||
use header::{DATE, HttpDate};
|
||||
|
||||
|
||||
header! {
|
||||
@ -22,13 +22,13 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::Date;
|
||||
/// use actix_web::http::header::Date;
|
||||
/// use std::time::SystemTime;
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(Date(SystemTime::now().into()));
|
||||
/// ```
|
||||
(Date, http::DATE) => [HttpDate]
|
||||
(Date, DATE) => [HttpDate]
|
||||
|
||||
test_date {
|
||||
test_header!(test1, vec![b"Tue, 15 Nov 1994 08:12:31 GMT"]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, EntityTag};
|
||||
use header::{ETAG, EntityTag};
|
||||
|
||||
header! {
|
||||
/// `ETag` header, defined in [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.3)
|
||||
@ -29,7 +29,7 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::{ETag, EntityTag};
|
||||
/// use actix_web::http::header::{ETag, EntityTag};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(ETag(EntityTag::new(false, "xyzzy".to_owned())));
|
||||
@ -37,12 +37,12 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::{ETag, EntityTag};
|
||||
/// use actix_web::http::header::{ETag, EntityTag};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(ETag(EntityTag::new(true, "xyzzy".to_owned())));
|
||||
/// ```
|
||||
(ETag, http::ETAG) => [EntityTag]
|
||||
(ETag, ETAG) => [EntityTag]
|
||||
|
||||
test_etag {
|
||||
// From the RFC
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, HttpDate};
|
||||
use header::{EXPIRES, HttpDate};
|
||||
|
||||
header! {
|
||||
/// `Expires` header, defined in [RFC7234](http://tools.ietf.org/html/rfc7234#section-5.3)
|
||||
@ -23,14 +23,14 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::Expires;
|
||||
/// use actix_web::http::header::Expires;
|
||||
/// use std::time::{SystemTime, Duration};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// let expiration = SystemTime::now() + Duration::from_secs(60 * 60 * 24);
|
||||
/// builder.set(Expires(expiration.into()));
|
||||
/// ```
|
||||
(Expires, http::EXPIRES) => [HttpDate]
|
||||
(Expires, EXPIRES) => [HttpDate]
|
||||
|
||||
test_expires {
|
||||
// Test case from RFC
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, EntityTag};
|
||||
use header::{IF_MATCH, EntityTag};
|
||||
|
||||
header! {
|
||||
/// `If-Match` header, defined in
|
||||
@ -31,7 +31,7 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::IfMatch;
|
||||
/// use actix_web::http::header::IfMatch;
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(IfMatch::Any);
|
||||
@ -39,7 +39,7 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::{IfMatch, EntityTag};
|
||||
/// use actix_web::http::header::{IfMatch, EntityTag};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(
|
||||
@ -50,7 +50,7 @@ header! {
|
||||
/// ])
|
||||
/// );
|
||||
/// ```
|
||||
(IfMatch, http::IF_MATCH) => {Any / (EntityTag)+}
|
||||
(IfMatch, IF_MATCH) => {Any / (EntityTag)+}
|
||||
|
||||
test_if_match {
|
||||
test_header!(
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, HttpDate};
|
||||
use header::{IF_MODIFIED_SINCE, HttpDate};
|
||||
|
||||
header! {
|
||||
/// `If-Modified-Since` header, defined in
|
||||
@ -23,14 +23,14 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::IfModifiedSince;
|
||||
/// use actix_web::http::header::IfModifiedSince;
|
||||
/// use std::time::{SystemTime, Duration};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
||||
/// builder.set(IfModifiedSince(modified.into()));
|
||||
/// ```
|
||||
(IfModifiedSince, http::IF_MODIFIED_SINCE) => [HttpDate]
|
||||
(IfModifiedSince, IF_MODIFIED_SINCE) => [HttpDate]
|
||||
|
||||
test_if_modified_since {
|
||||
// Test case from RFC
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, EntityTag};
|
||||
use header::{IF_NONE_MATCH, EntityTag};
|
||||
|
||||
header! {
|
||||
/// `If-None-Match` header, defined in
|
||||
@ -33,7 +33,7 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::IfNoneMatch;
|
||||
/// use actix_web::http::header::IfNoneMatch;
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(IfNoneMatch::Any);
|
||||
@ -41,7 +41,7 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::{IfNoneMatch, EntityTag};
|
||||
/// use actix_web::http::header::{IfNoneMatch, EntityTag};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(
|
||||
@ -52,7 +52,7 @@ header! {
|
||||
/// ])
|
||||
/// );
|
||||
/// ```
|
||||
(IfNoneMatch, http::IF_NONE_MATCH) => {Any / (EntityTag)+}
|
||||
(IfNoneMatch, IF_NONE_MATCH) => {Any / (EntityTag)+}
|
||||
|
||||
test_if_none_match {
|
||||
test_header!(test1, vec![b"\"xyzzy\""]);
|
||||
@ -67,18 +67,18 @@ header! {
|
||||
mod tests {
|
||||
use super::IfNoneMatch;
|
||||
use test::TestRequest;
|
||||
use header::{http, Header, EntityTag};
|
||||
use header::{IF_NONE_MATCH, Header, EntityTag};
|
||||
|
||||
#[test]
|
||||
fn test_if_none_match() {
|
||||
let mut if_none_match: Result<IfNoneMatch, _>;
|
||||
|
||||
let req = TestRequest::with_header(http::IF_NONE_MATCH, "*").finish();
|
||||
let req = TestRequest::with_header(IF_NONE_MATCH, "*").finish();
|
||||
if_none_match = Header::parse(&req);
|
||||
assert_eq!(if_none_match.ok(), Some(IfNoneMatch::Any));
|
||||
|
||||
let req = TestRequest::with_header(
|
||||
http::IF_NONE_MATCH, &b"\"foobar\", W/\"weak-etag\""[..]).finish();
|
||||
IF_NONE_MATCH, &b"\"foobar\", W/\"weak-etag\""[..]).finish();
|
||||
|
||||
if_none_match = Header::parse(&req);
|
||||
let mut entities: Vec<EntityTag> = Vec::new();
|
||||
|
@ -1,8 +1,10 @@
|
||||
use std::fmt::{self, Display, Write};
|
||||
use error::ParseError;
|
||||
use httpmessage::HttpMessage;
|
||||
use header::{http, from_one_raw_str};
|
||||
use header::{IntoHeaderValue, Header, EntityTag, HttpDate, Writer};
|
||||
use http::header;
|
||||
use header::from_one_raw_str;
|
||||
use header::{IntoHeaderValue, Header, HeaderName, HeaderValue,
|
||||
EntityTag, HttpDate, Writer, InvalidHeaderValueBytes};
|
||||
|
||||
/// `If-Range` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-3.2)
|
||||
///
|
||||
@ -34,7 +36,7 @@ use header::{IntoHeaderValue, Header, EntityTag, HttpDate, Writer};
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::{IfRange, EntityTag};
|
||||
/// use actix_web::http::header::{IfRange, EntityTag};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// builder.set(IfRange::EntityTag(EntityTag::new(false, "xyzzy".to_owned())));
|
||||
@ -42,7 +44,7 @@ use header::{IntoHeaderValue, Header, EntityTag, HttpDate, Writer};
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::IfRange;
|
||||
/// use actix_web::http::header::IfRange;
|
||||
/// use std::time::{SystemTime, Duration};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
@ -58,17 +60,19 @@ pub enum IfRange {
|
||||
}
|
||||
|
||||
impl Header for IfRange {
|
||||
fn name() -> http::HeaderName {
|
||||
http::IF_RANGE
|
||||
fn name() -> HeaderName {
|
||||
header::IF_RANGE
|
||||
}
|
||||
#[inline]
|
||||
fn parse<T>(msg: &T) -> Result<Self, ParseError> where T: HttpMessage
|
||||
{
|
||||
let etag: Result<EntityTag, _> = from_one_raw_str(msg.headers().get(http::IF_RANGE));
|
||||
let etag: Result<EntityTag, _> =
|
||||
from_one_raw_str(msg.headers().get(header::IF_RANGE));
|
||||
if let Ok(etag) = etag {
|
||||
return Ok(IfRange::EntityTag(etag));
|
||||
}
|
||||
let date: Result<HttpDate, _> = from_one_raw_str(msg.headers().get(http::IF_RANGE));
|
||||
let date: Result<HttpDate, _> =
|
||||
from_one_raw_str(msg.headers().get(header::IF_RANGE));
|
||||
if let Ok(date) = date {
|
||||
return Ok(IfRange::Date(date));
|
||||
}
|
||||
@ -86,12 +90,12 @@ impl Display for IfRange {
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for IfRange {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
let mut writer = Writer::new();
|
||||
let _ = write!(&mut writer, "{}", self);
|
||||
http::HeaderValue::from_shared(writer.take())
|
||||
HeaderValue::from_shared(writer.take())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, HttpDate};
|
||||
use header::{IF_UNMODIFIED_SINCE, HttpDate};
|
||||
|
||||
header! {
|
||||
/// `If-Unmodified-Since` header, defined in
|
||||
@ -24,14 +24,14 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::IfUnmodifiedSince;
|
||||
/// use actix_web::http::header::IfUnmodifiedSince;
|
||||
/// use std::time::{SystemTime, Duration};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
||||
/// builder.set(IfUnmodifiedSince(modified.into()));
|
||||
/// ```
|
||||
(IfUnmodifiedSince, http::IF_UNMODIFIED_SINCE) => [HttpDate]
|
||||
(IfUnmodifiedSince, IF_UNMODIFIED_SINCE) => [HttpDate]
|
||||
|
||||
test_if_unmodified_since {
|
||||
// Test case from RFC
|
||||
|
@ -1,4 +1,4 @@
|
||||
use header::{http, HttpDate};
|
||||
use header::{LAST_MODIFIED, HttpDate};
|
||||
|
||||
header! {
|
||||
/// `Last-Modified` header, defined in
|
||||
@ -23,14 +23,14 @@ header! {
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web::httpcodes;
|
||||
/// use actix_web::header::LastModified;
|
||||
/// use actix_web::http::header::LastModified;
|
||||
/// use std::time::{SystemTime, Duration};
|
||||
///
|
||||
/// let mut builder = httpcodes::HttpOk.build();
|
||||
/// let modified = SystemTime::now() - Duration::from_secs(60 * 60 * 24);
|
||||
/// builder.set(LastModified(modified.into()));
|
||||
/// ```
|
||||
(LastModified, http::LAST_MODIFIED) => [HttpDate]
|
||||
(LastModified, LAST_MODIFIED) => [HttpDate]
|
||||
|
||||
test_last_modified {
|
||||
// Test case from RFC
|
||||
|
@ -144,7 +144,7 @@ macro_rules! header {
|
||||
__hyper__deref!($id => Vec<$item>);
|
||||
impl $crate::header::Header for $id {
|
||||
#[inline]
|
||||
fn name() -> $crate::header::http::HeaderName {
|
||||
fn name() -> $crate::header::HeaderName {
|
||||
$name
|
||||
}
|
||||
#[inline]
|
||||
@ -162,13 +162,13 @@ macro_rules! header {
|
||||
}
|
||||
}
|
||||
impl $crate::header::IntoHeaderValue for $id {
|
||||
type Error = $crate::header::http::InvalidHeaderValueBytes;
|
||||
type Error = $crate::header::InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<$crate::header::http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
|
||||
use std::fmt::Write;
|
||||
let mut writer = $crate::header::Writer::new();
|
||||
let _ = write!(&mut writer, "{}", self);
|
||||
$crate::header::http::HeaderValue::from_shared(writer.take())
|
||||
$crate::header::HeaderValue::from_shared(writer.take())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -180,7 +180,7 @@ macro_rules! header {
|
||||
__hyper__deref!($id => Vec<$item>);
|
||||
impl $crate::header::Header for $id {
|
||||
#[inline]
|
||||
fn name() -> $crate::header::http::HeaderName {
|
||||
fn name() -> $crate::header::HeaderName {
|
||||
$name
|
||||
}
|
||||
#[inline]
|
||||
@ -198,13 +198,13 @@ macro_rules! header {
|
||||
}
|
||||
}
|
||||
impl $crate::header::IntoHeaderValue for $id {
|
||||
type Error = $crate::header::http::InvalidHeaderValueBytes;
|
||||
type Error = $crate::header::InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<$crate::header::http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
|
||||
use std::fmt::Write;
|
||||
let mut writer = $crate::header::Writer::new();
|
||||
let _ = write!(&mut writer, "{}", self);
|
||||
$crate::header::http::HeaderValue::from_shared(writer.take())
|
||||
$crate::header::HeaderValue::from_shared(writer.take())
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -216,7 +216,7 @@ macro_rules! header {
|
||||
__hyper__deref!($id => $value);
|
||||
impl $crate::header::Header for $id {
|
||||
#[inline]
|
||||
fn name() -> $crate::header::http::HeaderName {
|
||||
fn name() -> $crate::header::HeaderName {
|
||||
$name
|
||||
}
|
||||
#[inline]
|
||||
@ -234,9 +234,9 @@ macro_rules! header {
|
||||
}
|
||||
}
|
||||
impl $crate::header::IntoHeaderValue for $id {
|
||||
type Error = $crate::header::http::InvalidHeaderValueBytes;
|
||||
type Error = $crate::header::InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<$crate::header::http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
|
||||
self.0.try_into()
|
||||
}
|
||||
}
|
||||
@ -253,12 +253,12 @@ macro_rules! header {
|
||||
}
|
||||
impl $crate::header::Header for $id {
|
||||
#[inline]
|
||||
fn name() -> $crate::header::http::HeaderName {
|
||||
fn name() -> $crate::header::HeaderName {
|
||||
$name
|
||||
}
|
||||
#[inline]
|
||||
fn parse<T>(msg: &T) -> Result<Self, $crate::error::ParseError>
|
||||
where T: $crate::header::HttpMessage
|
||||
where T: $crate::HttpMessage
|
||||
{
|
||||
let any = msg.headers().get(Self::name()).and_then(|hdr| {
|
||||
hdr.to_str().ok().and_then(|hdr| Some(hdr.trim() == "*"))});
|
||||
@ -283,13 +283,13 @@ macro_rules! header {
|
||||
}
|
||||
}
|
||||
impl $crate::header::IntoHeaderValue for $id {
|
||||
type Error = $crate::header::http::InvalidHeaderValueBytes;
|
||||
type Error = $crate::header::InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<$crate::header::http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<$crate::header::HeaderValue, Self::Error> {
|
||||
use std::fmt::Write;
|
||||
let mut writer = $crate::header::Writer::new();
|
||||
let _ = write!(&mut writer, "{}", self);
|
||||
$crate::header::http::HeaderValue::from_shared(writer.take())
|
||||
$crate::header::HeaderValue::from_shared(writer.take())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -5,21 +5,15 @@ use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use http::{Error as HttpError};
|
||||
use http::header::GetAll;
|
||||
use modhttp::{Error as HttpError};
|
||||
use modhttp::header::GetAll;
|
||||
use mime::Mime;
|
||||
|
||||
pub use cookie::{Cookie, CookieBuilder};
|
||||
pub use http_range::HttpRange;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod http {
|
||||
pub use http::header::*;
|
||||
}
|
||||
pub use modhttp::header::*;
|
||||
|
||||
use error::ParseError;
|
||||
use httpmessage::HttpMessage;
|
||||
pub use httpresponse::ConnectionType;
|
||||
|
||||
mod common;
|
||||
mod shared;
|
||||
@ -34,7 +28,7 @@ pub use self::shared::*;
|
||||
pub trait Header where Self: IntoHeaderValue {
|
||||
|
||||
/// Returns the name of the header field
|
||||
fn name() -> http::HeaderName;
|
||||
fn name() -> HeaderName;
|
||||
|
||||
/// Parse a header
|
||||
fn parse<T: HttpMessage>(msg: &T) -> Result<Self, ParseError>;
|
||||
@ -47,69 +41,69 @@ pub trait IntoHeaderValue: Sized {
|
||||
type Error: Into<HttpError>;
|
||||
|
||||
/// Cast from PyObject to a concrete Python object type.
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error>;
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error>;
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for http::HeaderValue {
|
||||
type Error = http::InvalidHeaderValue;
|
||||
impl IntoHeaderValue for HeaderValue {
|
||||
type Error = InvalidHeaderValue;
|
||||
|
||||
#[inline]
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoHeaderValue for &'a str {
|
||||
type Error = http::InvalidHeaderValue;
|
||||
type Error = InvalidHeaderValue;
|
||||
|
||||
#[inline]
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
self.parse()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoHeaderValue for &'a [u8] {
|
||||
type Error = http::InvalidHeaderValue;
|
||||
type Error = InvalidHeaderValue;
|
||||
|
||||
#[inline]
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
http::HeaderValue::from_bytes(self)
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
HeaderValue::from_bytes(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for Bytes {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = InvalidHeaderValueBytes;
|
||||
|
||||
#[inline]
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
http::HeaderValue::from_shared(self)
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
HeaderValue::from_shared(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for Vec<u8> {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = InvalidHeaderValueBytes;
|
||||
|
||||
#[inline]
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
http::HeaderValue::from_shared(Bytes::from(self))
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
HeaderValue::from_shared(Bytes::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for String {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = InvalidHeaderValueBytes;
|
||||
|
||||
#[inline]
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
http::HeaderValue::from_shared(Bytes::from(self))
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
HeaderValue::from_shared(Bytes::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for Mime {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = InvalidHeaderValueBytes;
|
||||
|
||||
#[inline]
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
http::HeaderValue::from_shared(Bytes::from(format!("{}", self)))
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
HeaderValue::from_shared(Bytes::from(format!("{}", self)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,7 +200,7 @@ impl fmt::Write for Writer {
|
||||
#[inline]
|
||||
#[doc(hidden)]
|
||||
/// Reads a comma-delimited raw header into a Vec.
|
||||
pub fn from_comma_delimited<T: FromStr>(all: GetAll<http::HeaderValue>)
|
||||
pub fn from_comma_delimited<T: FromStr>(all: GetAll<HeaderValue>)
|
||||
-> Result<Vec<T>, ParseError>
|
||||
{
|
||||
let mut result = Vec::new();
|
||||
@ -225,7 +219,7 @@ pub fn from_comma_delimited<T: FromStr>(all: GetAll<http::HeaderValue>)
|
||||
#[inline]
|
||||
#[doc(hidden)]
|
||||
/// Reads a single string when parsing a header.
|
||||
pub fn from_one_raw_str<T: FromStr>(val: Option<&http::HeaderValue>)
|
||||
pub fn from_one_raw_str<T: FromStr>(val: Option<&HeaderValue>)
|
||||
-> Result<T, ParseError>
|
||||
{
|
||||
if let Some(line) = val {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::str::FromStr;
|
||||
use std::fmt::{self, Display, Write};
|
||||
use header::{http, Writer, IntoHeaderValue};
|
||||
use header::{HeaderValue, Writer, IntoHeaderValue, InvalidHeaderValueBytes};
|
||||
|
||||
/// check that each char in the slice is either:
|
||||
/// 1. `%x21`, or
|
||||
@ -144,12 +144,12 @@ impl FromStr for EntityTag {
|
||||
}
|
||||
|
||||
impl IntoHeaderValue for EntityTag {
|
||||
type Error = http::InvalidHeaderValueBytes;
|
||||
type Error = InvalidHeaderValueBytes;
|
||||
|
||||
fn try_into(self) -> Result<http::HeaderValue, Self::Error> {
|
||||
fn try_into(self) -> Result<HeaderValue, Self::Error> {
|
||||
let mut wrt = Writer::new();
|
||||
write!(wrt, "{}", self).unwrap();
|
||||
unsafe{Ok(http::HeaderValue::from_shared_unchecked(wrt.take()))}
|
||||
unsafe{Ok(HeaderValue::from_shared_unchecked(wrt.take()))}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user