1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-28 01:52:57 +01:00

Merge branch 'master' into payload_err

This commit is contained in:
Nikolay Kim 2018-06-02 15:04:22 -07:00 committed by GitHub
commit 7298c7aabf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 16 deletions

View File

@ -25,6 +25,8 @@
### Fixed ### Fixed
* Support chunked encoding for UrlEncoded body #262
* `HttpRequest::url_for()` for a named route with no variables segments #265 * `HttpRequest::url_for()` for a named route with no variables segments #265

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::str; use std::{fmt, str};
use bytes::Bytes; use bytes::Bytes;
use encoding::all::UTF_8; use encoding::all::UTF_8;
@ -115,6 +115,18 @@ where
} }
} }
impl<T: fmt::Debug> fmt::Debug for Path<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.fmt(f)
}
}
impl<T: fmt::Display> fmt::Display for Path<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.fmt(f)
}
}
/// Extract typed information from from the request's query. /// Extract typed information from from the request's query.
/// ///
/// ## Example /// ## Example
@ -175,13 +187,24 @@ where
#[inline] #[inline]
fn from_request(req: &HttpRequest<S>, _: &Self::Config) -> Self::Result { fn from_request(req: &HttpRequest<S>, _: &Self::Config) -> Self::Result {
let req = req.clone();
serde_urlencoded::from_str::<T>(req.query_string()) serde_urlencoded::from_str::<T>(req.query_string())
.map_err(|e| e.into()) .map_err(|e| e.into())
.map(Query) .map(Query)
} }
} }
impl<T: fmt::Debug> fmt::Debug for Query<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl<T: fmt::Display> fmt::Display for Query<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
/// Extract typed information from the request's body. /// Extract typed information from the request's body.
/// ///
/// To extract typed information from request's body, the type `T` must /// To extract typed information from request's body, the type `T` must
@ -252,6 +275,18 @@ where
} }
} }
impl<T: fmt::Debug> fmt::Debug for Form<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl<T: fmt::Display> fmt::Display for Form<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
/// Form extractor configuration /// Form extractor configuration
/// ///
/// ```rust /// ```rust

View File

@ -149,7 +149,6 @@ pub trait HttpMessage {
/// Returns error: /// Returns error:
/// ///
/// * content type is not `application/x-www-form-urlencoded` /// * content type is not `application/x-www-form-urlencoded`
/// * transfer encoding is `chunked`.
/// * content-length is greater than 256k /// * content-length is greater than 256k
/// ///
/// ## Server example /// ## Server example
@ -367,9 +366,7 @@ where
fn poll(&mut self) -> Poll<Self::Item, Self::Error> { fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
if let Some(req) = self.req.take() { if let Some(req) = self.req.take() {
if req.chunked().unwrap_or(false) { if let Some(len) = req.headers().get(header::CONTENT_LENGTH) {
return Err(UrlencodedError::Chunked);
} else if let Some(len) = req.headers().get(header::CONTENT_LENGTH) {
if let Ok(s) = len.to_str() { if let Ok(s) = len.to_str() {
if let Ok(len) = s.parse::<u64>() { if let Ok(len) = s.parse::<u64>() {
if len > 262_144 { if len > 262_144 {
@ -577,13 +574,6 @@ mod tests {
#[test] #[test]
fn test_urlencoded_error() { fn test_urlencoded_error() {
let req =
TestRequest::with_header(header::TRANSFER_ENCODING, "chunked").finish();
assert_eq!(
req.urlencoded::<Info>().poll().err().unwrap(),
UrlencodedError::Chunked
);
let req = TestRequest::with_header( let req = TestRequest::with_header(
header::CONTENT_TYPE, header::CONTENT_TYPE,
"application/x-www-form-urlencoded", "application/x-www-form-urlencoded",

View File

@ -283,9 +283,9 @@ impl<S> HttpRequest<S> {
/// Generate url for named resource /// Generate url for named resource
/// ///
/// ```rust /// ```rust
/// //#### # extern crate actix_web; /// # extern crate actix_web;
/// //#### # use actix_web::{App, HttpRequest, HttpResponse, http}; /// # use actix_web::{App, HttpRequest, HttpResponse, http};
/// //#### # /// #
/// fn index(req: HttpRequest) -> HttpResponse { /// fn index(req: HttpRequest) -> HttpResponse {
/// let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource /// let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource
/// HttpResponse::Ok().into() /// HttpResponse::Ok().into()