mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-26 02:19:22 +02:00
re-arrange modules and exports
This commit is contained in:
@ -178,14 +178,14 @@ impl<S> Application<S> where S: 'static {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::{Application, http, httpcodes};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new()
|
||||
/// .prefix("/app")
|
||||
/// .resource("/test", |r| {
|
||||
/// r.method(Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// r.method(http::Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(http::Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// })
|
||||
/// .finish();
|
||||
/// }
|
||||
@ -222,13 +222,13 @@ impl<S> Application<S> where S: 'static {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::{Application, http, httpcodes};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new()
|
||||
/// .resource("/test", |r| {
|
||||
/// r.method(Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// r.method(http::Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(http::Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
@ -277,7 +277,7 @@ impl<S> Application<S> where S: 'static {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::{Application, HttpRequest, HttpResponse, Result, httpcodes};
|
||||
///
|
||||
/// fn index(mut req: HttpRequest) -> Result<HttpResponse> {
|
||||
/// let url = req.url_for("youtube", &["oHg5SJYRHA0"])?;
|
||||
@ -315,14 +315,14 @@ impl<S> Application<S> where S: 'static {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::{Application, HttpRequest, http, httpcodes};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new()
|
||||
/// .handler("/app", |req: HttpRequest| {
|
||||
/// match *req.method() {
|
||||
/// Method::GET => httpcodes::HttpOk,
|
||||
/// Method::POST => httpcodes::HttpMethodNotAllowed,
|
||||
/// http::Method::GET => httpcodes::HttpOk,
|
||||
/// http::Method::POST => httpcodes::HttpMethodNotAllowed,
|
||||
/// _ => httpcodes::HttpNotFound,
|
||||
/// }});
|
||||
/// }
|
||||
@ -352,14 +352,14 @@ impl<S> Application<S> where S: 'static {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::{Application, http, httpcodes, fs, middleware};
|
||||
///
|
||||
/// // this function could be located in different module
|
||||
/// fn config(app: Application) -> Application {
|
||||
/// app
|
||||
/// .resource("/test", |r| {
|
||||
/// r.method(Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// r.method(http::Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(http::Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// })
|
||||
/// }
|
||||
///
|
||||
|
@ -312,16 +312,14 @@ impl ClientRequestBuilder {
|
||||
/// ```rust
|
||||
/// # extern crate mime;
|
||||
/// # extern crate actix_web;
|
||||
/// # use actix_web::*;
|
||||
/// # use actix_web::httpcodes::*;
|
||||
/// # use actix_web::client::*;
|
||||
/// #
|
||||
/// use actix_web::header;
|
||||
/// use actix_web::{client, http};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let req = ClientRequest::build()
|
||||
/// .set(header::Date::now())
|
||||
/// .set(header::ContentType(mime::TEXT_HTML))
|
||||
/// let req = client::ClientRequest::build()
|
||||
/// .set(http::header::Date::now())
|
||||
/// .set(http::header::ContentType(mime::TEXT_HTML))
|
||||
/// .finish().unwrap();
|
||||
/// }
|
||||
/// ```
|
||||
@ -446,16 +444,12 @@ impl ClientRequestBuilder {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// # use actix_web::*;
|
||||
/// # use actix_web::httpcodes::*;
|
||||
/// #
|
||||
/// use actix_web::header::Cookie;
|
||||
/// use actix_web::client::ClientRequest;
|
||||
/// use actix_web::{client, http};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let req = ClientRequest::build()
|
||||
/// let req = client::ClientRequest::build()
|
||||
/// .cookie(
|
||||
/// Cookie::build("name", "value")
|
||||
/// http::Cookie::build("name", "value")
|
||||
/// .domain("www.rust-lang.org")
|
||||
/// .path("/")
|
||||
/// .secure(true)
|
||||
|
19
src/de.rs
19
src/de.rs
@ -19,8 +19,7 @@ use httprequest::HttpRequest;
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// # use actix_web::*;
|
||||
/// use actix_web::Path;
|
||||
/// use actix_web::{Application, Path, Result, http};
|
||||
///
|
||||
/// /// extract path info from "/{username}/{count}/?index.html" url
|
||||
/// /// {username} - deserializes to a String
|
||||
@ -32,7 +31,7 @@ use httprequest::HttpRequest;
|
||||
/// fn main() {
|
||||
/// let app = Application::new().resource(
|
||||
/// "/{username}/{count}/?index.html", // <- define path parameters
|
||||
/// |r| r.method(Method::GET).with(index)); // <- use `with` extractor
|
||||
/// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
@ -44,8 +43,7 @@ use httprequest::HttpRequest;
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// # use actix_web::*;
|
||||
/// use actix_web::Path;
|
||||
/// use actix_web::{Application, Path, Result, http};
|
||||
///
|
||||
/// #[derive(Deserialize)]
|
||||
/// struct Info {
|
||||
@ -60,7 +58,7 @@ use httprequest::HttpRequest;
|
||||
/// fn main() {
|
||||
/// let app = Application::new().resource(
|
||||
/// "/{username}/index.html", // <- define path parameters
|
||||
/// |r| r.method(Method::GET).with(index)); // <- use `with` extractor
|
||||
/// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor
|
||||
/// }
|
||||
/// ```
|
||||
pub struct Path<T>{
|
||||
@ -111,8 +109,7 @@ impl<T, S> FromRequest<S> for Path<T>
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// # use actix_web::*;
|
||||
/// use actix_web::Query;
|
||||
/// use actix_web::{Application, Query, http};
|
||||
///
|
||||
/// #[derive(Deserialize)]
|
||||
/// struct Info {
|
||||
@ -121,14 +118,14 @@ impl<T, S> FromRequest<S> for Path<T>
|
||||
///
|
||||
/// // use `with` extractor for query info
|
||||
/// // this handler get called only if request's query contains `username` field
|
||||
/// fn index(info: Query<Info>) -> Result<String> {
|
||||
/// Ok(format!("Welcome {}!", info.username))
|
||||
/// fn index(info: Query<Info>) -> String {
|
||||
/// format!("Welcome {}!", info.username)
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new().resource(
|
||||
/// "/index.html",
|
||||
/// |r| r.method(Method::GET).with(index)); // <- use `with` extractor
|
||||
/// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor
|
||||
/// }
|
||||
/// ```
|
||||
pub struct Query<T>(T);
|
||||
|
@ -178,8 +178,8 @@ impl Responder for NamedFile {
|
||||
fn respond_to(self, req: HttpRequest) -> Result<HttpResponse, io::Error> {
|
||||
if self.only_get && *req.method() != Method::GET && *req.method() != Method::HEAD {
|
||||
return Ok(HttpMethodNotAllowed.build()
|
||||
.header(header::http::CONTENT_TYPE, "text/plain")
|
||||
.header(header::http::ALLOW, "GET, HEAD")
|
||||
.header(header::CONTENT_TYPE, "text/plain")
|
||||
.header(header::ALLOW, "GET, HEAD")
|
||||
.body("This resource only supports GET and HEAD.").unwrap())
|
||||
}
|
||||
|
||||
@ -466,7 +466,7 @@ impl<S: 'static> Handler<S> for StaticFiles<S> {
|
||||
}
|
||||
new_path.push_str(redir_index);
|
||||
HttpFound.build()
|
||||
.header(header::http::LOCATION, new_path.as_str())
|
||||
.header(header::LOCATION, new_path.as_str())
|
||||
.finish().unwrap()
|
||||
.respond_to(req.without_state())
|
||||
} else if self.show_index {
|
||||
|
@ -373,7 +373,6 @@ impl<S, H, F, R, E> RouteHandler<S> for AsyncHandler<S, H, F, R, E>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Access to an application state
|
||||
///
|
||||
/// `S` - application state type
|
||||
@ -384,9 +383,8 @@ impl<S, H, F, R, E> RouteHandler<S> for AsyncHandler<S, H, F, R, E>
|
||||
/// # extern crate bytes;
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// # use actix_web::*;
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// use actix_web::State;
|
||||
/// use actix_web::{Application, Path, State, http};
|
||||
///
|
||||
/// /// Application state
|
||||
/// struct App {msg: &'static str}
|
||||
@ -397,14 +395,14 @@ impl<S, H, F, R, E> RouteHandler<S> for AsyncHandler<S, H, F, R, E>
|
||||
/// }
|
||||
///
|
||||
/// /// extract path info using serde
|
||||
/// fn index(state: State<App>, info: Path<Info>) -> Result<String> {
|
||||
/// Ok(format!("{} {}!", state.msg, info.username))
|
||||
/// fn index(state: State<App>, info: Path<Info>) -> String {
|
||||
/// format!("{} {}!", state.msg, info.username)
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::with_state(App{msg: "Welcome"}).resource(
|
||||
/// "/{username}/index.html", // <- define path parameters
|
||||
/// |r| r.method(Method::GET).with2(index)); // <- use `with` extractor
|
||||
/// "/{username}/index.html", // <- define path parameters
|
||||
/// |r| r.method(http::Method::GET).with2(index)); // <- use `with` extractor
|
||||
/// }
|
||||
/// ```
|
||||
pub struct State<S> (HttpRequest<S>);
|
||||
|
@ -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()))}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ use httpresponse::HttpResponse;
|
||||
/// # extern crate actix_web;
|
||||
/// # #[macro_use] extern crate serde_derive;
|
||||
/// # use actix_web::*;
|
||||
/// use actix_web::helpers::NormalizePath;
|
||||
/// use actix_web::http::NormalizePath;
|
||||
/// #
|
||||
/// # fn index(req: HttpRequest) -> httpcodes::StaticResponse {
|
||||
/// # httpcodes::HttpOk
|
||||
|
119
src/httpcodes.rs
119
src/httpcodes.rs
@ -71,113 +71,6 @@ pub const HttpInsufficientStorage: StaticResponse =
|
||||
StaticResponse(StatusCode::INSUFFICIENT_STORAGE);
|
||||
pub const HttpLoopDetected: StaticResponse = StaticResponse(StatusCode::LOOP_DETECTED);
|
||||
|
||||
#[doc(hidden)]
|
||||
pub const HTTPOk: StaticResponse = StaticResponse(StatusCode::OK);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPCreated: StaticResponse = StaticResponse(StatusCode::CREATED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPAccepted: StaticResponse = StaticResponse(StatusCode::ACCEPTED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPNonAuthoritativeInformation: StaticResponse =
|
||||
StaticResponse(StatusCode::NON_AUTHORITATIVE_INFORMATION);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPNoContent: StaticResponse = StaticResponse(StatusCode::NO_CONTENT);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPResetContent: StaticResponse = StaticResponse(StatusCode::RESET_CONTENT);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPPartialContent: StaticResponse = StaticResponse(StatusCode::PARTIAL_CONTENT);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPMultiStatus: StaticResponse = StaticResponse(StatusCode::MULTI_STATUS);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPAlreadyReported: StaticResponse = StaticResponse(StatusCode::ALREADY_REPORTED);
|
||||
|
||||
#[doc(hidden)]
|
||||
pub const HTTPMultipleChoices: StaticResponse = StaticResponse(StatusCode::MULTIPLE_CHOICES);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPMovedPermanenty: StaticResponse = StaticResponse(StatusCode::MOVED_PERMANENTLY);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPFound: StaticResponse = StaticResponse(StatusCode::FOUND);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPSeeOther: StaticResponse = StaticResponse(StatusCode::SEE_OTHER);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPNotModified: StaticResponse = StaticResponse(StatusCode::NOT_MODIFIED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPUseProxy: StaticResponse = StaticResponse(StatusCode::USE_PROXY);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPTemporaryRedirect: StaticResponse =
|
||||
StaticResponse(StatusCode::TEMPORARY_REDIRECT);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPPermanentRedirect: StaticResponse =
|
||||
StaticResponse(StatusCode::PERMANENT_REDIRECT);
|
||||
|
||||
#[doc(hidden)]
|
||||
pub const HTTPBadRequest: StaticResponse = StaticResponse(StatusCode::BAD_REQUEST);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPUnauthorized: StaticResponse = StaticResponse(StatusCode::UNAUTHORIZED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPPaymentRequired: StaticResponse = StaticResponse(StatusCode::PAYMENT_REQUIRED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPForbidden: StaticResponse = StaticResponse(StatusCode::FORBIDDEN);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPNotFound: StaticResponse = StaticResponse(StatusCode::NOT_FOUND);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPMethodNotAllowed: StaticResponse =
|
||||
StaticResponse(StatusCode::METHOD_NOT_ALLOWED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPNotAcceptable: StaticResponse = StaticResponse(StatusCode::NOT_ACCEPTABLE);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPProxyAuthenticationRequired: StaticResponse =
|
||||
StaticResponse(StatusCode::PROXY_AUTHENTICATION_REQUIRED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPRequestTimeout: StaticResponse = StaticResponse(StatusCode::REQUEST_TIMEOUT);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPConflict: StaticResponse = StaticResponse(StatusCode::CONFLICT);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPGone: StaticResponse = StaticResponse(StatusCode::GONE);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPLengthRequired: StaticResponse = StaticResponse(StatusCode::LENGTH_REQUIRED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPPreconditionFailed: StaticResponse =
|
||||
StaticResponse(StatusCode::PRECONDITION_FAILED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPPayloadTooLarge: StaticResponse = StaticResponse(StatusCode::PAYLOAD_TOO_LARGE);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPUriTooLong: StaticResponse = StaticResponse(StatusCode::URI_TOO_LONG);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPUnsupportedMediaType: StaticResponse =
|
||||
StaticResponse(StatusCode::UNSUPPORTED_MEDIA_TYPE);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPRangeNotSatisfiable: StaticResponse =
|
||||
StaticResponse(StatusCode::RANGE_NOT_SATISFIABLE);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPExpectationFailed: StaticResponse =
|
||||
StaticResponse(StatusCode::EXPECTATION_FAILED);
|
||||
|
||||
#[doc(hidden)]
|
||||
pub const HTTPInternalServerError: StaticResponse =
|
||||
StaticResponse(StatusCode::INTERNAL_SERVER_ERROR);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPNotImplemented: StaticResponse = StaticResponse(StatusCode::NOT_IMPLEMENTED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPBadGateway: StaticResponse = StaticResponse(StatusCode::BAD_GATEWAY);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPServiceUnavailable: StaticResponse =
|
||||
StaticResponse(StatusCode::SERVICE_UNAVAILABLE);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPGatewayTimeout: StaticResponse =
|
||||
StaticResponse(StatusCode::GATEWAY_TIMEOUT);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPVersionNotSupported: StaticResponse =
|
||||
StaticResponse(StatusCode::HTTP_VERSION_NOT_SUPPORTED);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPVariantAlsoNegotiates: StaticResponse =
|
||||
StaticResponse(StatusCode::VARIANT_ALSO_NEGOTIATES);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPInsufficientStorage: StaticResponse =
|
||||
StaticResponse(StatusCode::INSUFFICIENT_STORAGE);
|
||||
#[doc(hidden)]
|
||||
pub const HTTPLoopDetected: StaticResponse = StaticResponse(StatusCode::LOOP_DETECTED);
|
||||
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct StaticResponse(StatusCode);
|
||||
@ -281,32 +174,32 @@ impl HttpResponse {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use http::StatusCode;
|
||||
use super::{HTTPOk, HTTPBadRequest, Body, HttpResponse};
|
||||
use super::{HttpOk, HttpBadRequest, Body, HttpResponse};
|
||||
|
||||
#[test]
|
||||
fn test_build() {
|
||||
let resp = HTTPOk.build().body(Body::Empty).unwrap();
|
||||
let resp = HttpOk.build().body(Body::Empty).unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response() {
|
||||
let resp: HttpResponse = HTTPOk.into();
|
||||
let resp: HttpResponse = HttpOk.into();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from() {
|
||||
let resp: HttpResponse = HTTPOk.into();
|
||||
let resp: HttpResponse = HttpOk.into();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_reason() {
|
||||
let resp: HttpResponse = HTTPOk.into();
|
||||
let resp: HttpResponse = HttpOk.into();
|
||||
assert_eq!(resp.reason(), "OK");
|
||||
|
||||
let resp = HTTPBadRequest.with_reason("test");
|
||||
let resp = HttpBadRequest.with_reason("test");
|
||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
assert_eq!(resp.reason(), "test");
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ pub trait HttpMessage {
|
||||
/// }
|
||||
/// })
|
||||
/// .finish() // <- Stream::finish() combinator from actix
|
||||
/// .map(|_| httpcodes::HTTPOk.into())
|
||||
/// .map(|_| httpcodes::HttpOk.into())
|
||||
/// .responder()
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
|
@ -279,8 +279,8 @@ impl<S> HttpRequest<S> {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// # use actix_web::*;
|
||||
/// # use actix_web::httpcodes::*;
|
||||
/// # use actix_web::{Application, HttpRequest, HttpResponse, http};
|
||||
/// # use actix_web::httpcodes::HttpOk;
|
||||
/// #
|
||||
/// fn index(req: HttpRequest) -> HttpResponse {
|
||||
/// let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource
|
||||
@ -291,7 +291,7 @@ impl<S> HttpRequest<S> {
|
||||
/// let app = Application::new()
|
||||
/// .resource("/test/{one}/{two}/{three}", |r| {
|
||||
/// r.name("foo"); // <- set resource name, then it could be used in `url_for`
|
||||
/// r.method(Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(http::Method::GET).f(|_| HttpOk);
|
||||
/// })
|
||||
/// .finish();
|
||||
/// }
|
||||
|
@ -283,14 +283,11 @@ impl HttpResponseBuilder {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// # use actix_web::*;
|
||||
/// # use actix_web::httpcodes::*;
|
||||
/// #
|
||||
/// use actix_web::header;
|
||||
/// use actix_web::{HttpRequest, HttpResponse, Result, http, httpcodes};
|
||||
///
|
||||
/// fn index(req: HttpRequest) -> Result<HttpResponse> {
|
||||
/// Ok(HttpOk.build()
|
||||
/// .set(header::IfModifiedSince("Sun, 07 Nov 1994 08:48:37 GMT".parse()?))
|
||||
/// Ok(httpcodes::HttpOk.build()
|
||||
/// .set(http::header::IfModifiedSince("Sun, 07 Nov 1994 08:48:37 GMT".parse()?))
|
||||
/// .finish()?)
|
||||
/// }
|
||||
/// fn main() {}
|
||||
@ -432,15 +429,12 @@ impl HttpResponseBuilder {
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// # use actix_web::*;
|
||||
/// # use actix_web::httpcodes::*;
|
||||
/// #
|
||||
/// use actix_web::header::Cookie;
|
||||
/// use actix_web::{HttpRequest, HttpResponse, Result, http, httpcodes};
|
||||
///
|
||||
/// fn index(req: HttpRequest) -> Result<HttpResponse> {
|
||||
/// Ok(HttpOk.build()
|
||||
/// Ok(httpcodes::HttpOk.build()
|
||||
/// .cookie(
|
||||
/// Cookie::build("name", "value")
|
||||
/// http::Cookie::build("name", "value")
|
||||
/// .domain("www.rust-lang.org")
|
||||
/// .path("/")
|
||||
/// .secure(true)
|
||||
@ -876,7 +870,7 @@ mod tests {
|
||||
use http::{Method, Uri};
|
||||
use http::header::{COOKIE, CONTENT_TYPE, HeaderValue};
|
||||
use body::Binary;
|
||||
use {header, httpcodes};
|
||||
use {http, httpcodes};
|
||||
|
||||
#[test]
|
||||
fn test_debug() {
|
||||
@ -900,7 +894,7 @@ mod tests {
|
||||
|
||||
let resp = httpcodes::HttpOk
|
||||
.build()
|
||||
.cookie(header::Cookie::build("name", "value")
|
||||
.cookie(http::Cookie::build("name", "value")
|
||||
.domain("www.rust-lang.org")
|
||||
.path("/test")
|
||||
.http_only(true)
|
||||
|
@ -51,8 +51,7 @@ use httpresponse::HttpResponse;
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// # use actix_web::*;
|
||||
/// use actix_web::Json;
|
||||
/// use actix_web::{Application, Json, Result, http};
|
||||
///
|
||||
/// #[derive(Deserialize)]
|
||||
/// struct Info {
|
||||
@ -67,7 +66,7 @@ use httpresponse::HttpResponse;
|
||||
/// fn main() {
|
||||
/// let app = Application::new().resource(
|
||||
/// "/index.html",
|
||||
/// |r| r.method(Method::POST).with(index)); // <- use `with` extractor
|
||||
/// |r| r.method(http::Method::POST).with(index)); // <- use `with` extractor
|
||||
/// }
|
||||
/// ```
|
||||
pub struct Json<T>(pub T);
|
||||
@ -139,8 +138,9 @@ impl<T, S> FromRequest<S> for Json<T>
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// # #[macro_use] extern crate serde_derive;
|
||||
/// use actix_web::*;
|
||||
/// use futures::future::Future;
|
||||
/// use actix_web::{Application, AsyncResponder,
|
||||
/// HttpRequest, HttpResponse, HttpMessage, Error, httpcodes};
|
||||
///
|
||||
/// #[derive(Deserialize, Debug)]
|
||||
/// struct MyObj {
|
||||
|
30
src/lib.rs
30
src/lib.rs
@ -67,7 +67,7 @@ extern crate tokio_core;
|
||||
extern crate mio;
|
||||
extern crate net2;
|
||||
extern crate cookie;
|
||||
extern crate http;
|
||||
extern crate http as modhttp;
|
||||
extern crate httparse;
|
||||
extern crate http_range;
|
||||
extern crate mime;
|
||||
@ -108,6 +108,8 @@ mod body;
|
||||
mod context;
|
||||
mod de;
|
||||
mod handler;
|
||||
mod header;
|
||||
mod helpers;
|
||||
mod httpmessage;
|
||||
mod httprequest;
|
||||
mod httpresponse;
|
||||
@ -125,8 +127,6 @@ pub mod client;
|
||||
pub mod fs;
|
||||
pub mod ws;
|
||||
pub mod error;
|
||||
pub mod header;
|
||||
pub mod helpers;
|
||||
pub mod httpcodes;
|
||||
pub mod multipart;
|
||||
pub mod middleware;
|
||||
@ -145,9 +145,6 @@ pub use handler::{Either, Responder, AsyncResponder, FutureResponse, State};
|
||||
pub use context::HttpContext;
|
||||
pub use server::HttpServer;
|
||||
|
||||
// re-exports
|
||||
pub use http::{Method, StatusCode};
|
||||
|
||||
#[cfg(feature="openssl")]
|
||||
pub(crate) const HAS_OPENSSL: bool = true;
|
||||
#[cfg(not(feature="openssl"))]
|
||||
@ -182,3 +179,24 @@ pub mod dev {
|
||||
pub use httpmessage::{UrlEncoded, MessageBody};
|
||||
pub use httpresponse::HttpResponseBuilder;
|
||||
}
|
||||
|
||||
pub mod http {
|
||||
//! Various http related types
|
||||
|
||||
// re-exports
|
||||
pub use modhttp::{Method, StatusCode, Version};
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use modhttp::{uri, Uri, Error, Extensions, HeaderMap, HttpTryFrom};
|
||||
|
||||
pub use http_range::HttpRange;
|
||||
pub use cookie::{Cookie, CookieBuilder};
|
||||
|
||||
pub use helpers::NormalizePath;
|
||||
|
||||
pub mod header {
|
||||
pub use ::header::*;
|
||||
}
|
||||
pub use header::ContentEncoding;
|
||||
pub use httpresponse::ConnectionType;
|
||||
}
|
||||
|
@ -17,10 +17,8 @@
|
||||
//! # Example
|
||||
//!
|
||||
//! ```rust
|
||||
//! # extern crate http;
|
||||
//! # extern crate actix_web;
|
||||
//! # use actix_web::*;
|
||||
//! use http::header;
|
||||
//! use actix_web::{Application, HttpRequest, http, httpcodes};
|
||||
//! use actix_web::middleware::cors;
|
||||
//!
|
||||
//! fn index(mut req: HttpRequest) -> &'static str {
|
||||
@ -33,13 +31,13 @@
|
||||
//! cors::Cors::build() // <- Construct CORS middleware
|
||||
//! .allowed_origin("https://www.rust-lang.org/")
|
||||
//! .allowed_methods(vec!["GET", "POST"])
|
||||
//! .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
|
||||
//! .allowed_header(header::CONTENT_TYPE)
|
||||
//! .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
|
||||
//! .allowed_header(http::header::CONTENT_TYPE)
|
||||
//! .max_age(3600)
|
||||
//! .finish().expect("Can not create CORS middleware")
|
||||
//! .register(r); // <- Register CORS middleware
|
||||
//! r.method(Method::GET).f(|_| httpcodes::HttpOk);
|
||||
//! r.method(Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
//! r.method(http::Method::GET).f(|_| httpcodes::HttpOk);
|
||||
//! r.method(http::Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
//! })
|
||||
//! .finish();
|
||||
//! }
|
||||
|
@ -22,11 +22,10 @@
|
||||
//!
|
||||
//! ```
|
||||
//! # extern crate actix_web;
|
||||
//! # use actix_web::*;
|
||||
//!
|
||||
//! use actix_web::{Application, HttpRequest, http, httpcodes};
|
||||
//! use actix_web::middleware::csrf;
|
||||
//!
|
||||
//! fn handle_post(_req: HttpRequest) -> &'static str {
|
||||
//! fn handle_post(_: HttpRequest) -> &'static str {
|
||||
//! "This action should only be triggered with requests from the same site"
|
||||
//! }
|
||||
//!
|
||||
@ -37,8 +36,8 @@
|
||||
//! .allowed_origin("https://www.example.com")
|
||||
//! .finish())
|
||||
//! .resource("/", |r| {
|
||||
//! r.method(Method::GET).f(|_| httpcodes::HttpOk);
|
||||
//! r.method(Method::POST).f(handle_post);
|
||||
//! r.method(http::Method::GET).f(|_| httpcodes::HttpOk);
|
||||
//! r.method(http::Method::POST).f(handle_post);
|
||||
//! })
|
||||
//! .finish();
|
||||
//! }
|
||||
|
@ -13,7 +13,7 @@ use middleware::{Response, Middleware};
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::{Application, http, httpcodes, middleware};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new()
|
||||
@ -22,8 +22,8 @@ use middleware::{Response, Middleware};
|
||||
/// .header("X-Version", "0.2")
|
||||
/// .finish())
|
||||
/// .resource("/test", |r| {
|
||||
/// r.method(Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// r.method(http::Method::GET).f(|_| httpcodes::HttpOk);
|
||||
/// r.method(http::Method::HEAD).f(|_| httpcodes::HttpMethodNotAllowed);
|
||||
/// })
|
||||
/// .finish();
|
||||
/// }
|
||||
|
@ -25,12 +25,12 @@ use with::WithHandler;
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::{Application, HttpResponse, http};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new()
|
||||
/// .resource(
|
||||
/// "/", |r| r.method(Method::GET).f(|r| HttpResponse::Ok()))
|
||||
/// "/", |r| r.method(http::Method::GET).f(|r| HttpResponse::Ok()))
|
||||
/// .finish();
|
||||
/// }
|
||||
pub struct Resource<S=()> {
|
||||
|
14
src/route.rs
14
src/route.rs
@ -110,8 +110,7 @@ impl<S: 'static> Route<S> {
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::Path;
|
||||
/// use actix_web::{Application, Path, Result, http};
|
||||
///
|
||||
/// #[derive(Deserialize)]
|
||||
/// struct Info {
|
||||
@ -125,8 +124,8 @@ impl<S: 'static> Route<S> {
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new().resource(
|
||||
/// "/{username}/index.html", // <- define path parameters
|
||||
/// |r| r.method(Method::GET).with(index)); // <- use `with` extractor
|
||||
/// "/{username}/index.html", // <- define path parameters
|
||||
/// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor
|
||||
/// }
|
||||
/// ```
|
||||
pub fn with<T, H>(&mut self, handler: H)
|
||||
@ -143,8 +142,7 @@ impl<S: 'static> Route<S> {
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// use actix_web::*;
|
||||
/// use actix_web::Path;
|
||||
/// use actix_web::{Application, Query, Path, Result, http};
|
||||
///
|
||||
/// #[derive(Deserialize)]
|
||||
/// struct PParam {
|
||||
@ -163,8 +161,8 @@ impl<S: 'static> Route<S> {
|
||||
///
|
||||
/// fn main() {
|
||||
/// let app = Application::new().resource(
|
||||
/// "/{username}/index.html", // <- define path parameters
|
||||
/// |r| r.method(Method::GET).with2(index)); // <- use `with` extractor
|
||||
/// "/{username}/index.html", // <- define path parameters
|
||||
/// |r| r.method(http::Method::GET).with2(index)); // <- use `with` extractor
|
||||
/// }
|
||||
/// ```
|
||||
pub fn with2<T1, T2, F, R>(&mut self, handler: F)
|
||||
|
@ -8,7 +8,7 @@ use std::net::SocketAddr;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use actix::Arbiter;
|
||||
use http::request::Parts;
|
||||
use modhttp::request::Parts;
|
||||
use http2::{Reason, RecvStream};
|
||||
use http2::server::{self, Connection, Handshake, SendResponse};
|
||||
use bytes::{Buf, Bytes};
|
||||
|
@ -6,7 +6,9 @@ use bytes::{Bytes, BytesMut};
|
||||
use futures::{Async, Poll};
|
||||
use http2::{Reason, SendStream};
|
||||
use http2::server::SendResponse;
|
||||
use http::{Version, HttpTryFrom, Response};
|
||||
use modhttp::Response;
|
||||
|
||||
use http::{Version, HttpTryFrom};
|
||||
use http::header::{HeaderValue, CONNECTION, TRANSFER_ENCODING, DATE, CONTENT_LENGTH};
|
||||
|
||||
use body::{Body, Binary};
|
||||
|
Reference in New Issue
Block a user