diff --git a/CHANGES.md b/CHANGES.md index d1e4e6f6..367354a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,6 +25,8 @@ ### Fixed +* Support chunked encoding for UrlEncoded body #262 + * `HttpRequest::url_for()` for a named route with no variables segments #265 diff --git a/src/extractor.rs b/src/extractor.rs index 3d77853a..175e948b 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; -use std::str; +use std::{fmt, str}; use bytes::Bytes; use encoding::all::UTF_8; @@ -115,6 +115,18 @@ where } } +impl fmt::Debug for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.inner.fmt(f) + } +} + +impl fmt::Display for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.inner.fmt(f) + } +} + /// Extract typed information from from the request's query. /// /// ## Example @@ -175,13 +187,24 @@ where #[inline] fn from_request(req: &HttpRequest, _: &Self::Config) -> Self::Result { - let req = req.clone(); serde_urlencoded::from_str::(req.query_string()) .map_err(|e| e.into()) .map(Query) } } +impl fmt::Debug for Query { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + +impl fmt::Display for Query { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + /// Extract typed information from the request's body. /// /// To extract typed information from request's body, the type `T` must @@ -252,6 +275,18 @@ where } } +impl fmt::Debug for Form { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + +impl fmt::Display for Form { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + /// Form extractor configuration /// /// ```rust diff --git a/src/httpmessage.rs b/src/httpmessage.rs index 1e57d386..a9d68d3a 100644 --- a/src/httpmessage.rs +++ b/src/httpmessage.rs @@ -149,7 +149,6 @@ pub trait HttpMessage { /// Returns error: /// /// * content type is not `application/x-www-form-urlencoded` - /// * transfer encoding is `chunked`. /// * content-length is greater than 256k /// /// ## Server example @@ -367,9 +366,7 @@ where fn poll(&mut self) -> Poll { if let Some(req) = self.req.take() { - if req.chunked().unwrap_or(false) { - return Err(UrlencodedError::Chunked); - } else if let Some(len) = req.headers().get(header::CONTENT_LENGTH) { + if let Some(len) = req.headers().get(header::CONTENT_LENGTH) { if let Ok(s) = len.to_str() { if let Ok(len) = s.parse::() { if len > 262_144 { @@ -577,13 +574,6 @@ mod tests { #[test] fn test_urlencoded_error() { - let req = - TestRequest::with_header(header::TRANSFER_ENCODING, "chunked").finish(); - assert_eq!( - req.urlencoded::().poll().err().unwrap(), - UrlencodedError::Chunked - ); - let req = TestRequest::with_header( header::CONTENT_TYPE, "application/x-www-form-urlencoded", diff --git a/src/httprequest.rs b/src/httprequest.rs index 1d9f6245..d852bc74 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -283,9 +283,9 @@ impl HttpRequest { /// Generate url for named resource /// /// ```rust - /// //#### # extern crate actix_web; - /// //#### # use actix_web::{App, HttpRequest, HttpResponse, http}; - /// //#### # + /// # extern crate actix_web; + /// # use actix_web::{App, HttpRequest, HttpResponse, http}; + /// # /// fn index(req: HttpRequest) -> HttpResponse { /// let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource /// HttpResponse::Ok().into()