mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
Fix panic on invalid URL characters #130
This commit is contained in:
parent
b942bcc4a6
commit
5a25fd95f5
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
* Fix long client urls #129
|
* Fix long client urls #129
|
||||||
|
|
||||||
|
* Fix panic on invalid URL characters #130
|
||||||
|
|
||||||
* Fix client connection pooling
|
* Fix client connection pooling
|
||||||
|
|
||||||
* Use more ergonomic `actix_web::Error` instead of `http::Error` for `HttpResponseBuilder::body()`
|
* Use more ergonomic `actix_web::Error` instead of `http::Error` for `HttpResponseBuilder::body()`
|
||||||
|
@ -126,7 +126,7 @@ impl HttpResponseParser {
|
|||||||
let mut resp = httparse::Response::new(&mut headers);
|
let mut resp = httparse::Response::new(&mut headers);
|
||||||
match resp.parse(b)? {
|
match resp.parse(b)? {
|
||||||
httparse::Status::Complete(len) => {
|
httparse::Status::Complete(len) => {
|
||||||
let version = if resp.version.unwrap() == 1 {
|
let version = if resp.version.unwrap_or(1) == 1 {
|
||||||
Version::HTTP_11
|
Version::HTTP_11
|
||||||
} else {
|
} else {
|
||||||
Version::HTTP_10
|
Version::HTTP_10
|
||||||
|
13
src/error.rs
13
src/error.rs
@ -8,11 +8,10 @@ use cookie;
|
|||||||
use httparse;
|
use httparse;
|
||||||
use actix::MailboxError;
|
use actix::MailboxError;
|
||||||
use futures::Canceled;
|
use futures::Canceled;
|
||||||
use failure;
|
use failure::{self, Fail, Backtrace};
|
||||||
use failure::{Fail, Backtrace};
|
|
||||||
use http2::Error as Http2Error;
|
use http2::Error as Http2Error;
|
||||||
use http::{header, StatusCode, Error as HttpError};
|
use http::{header, StatusCode, Error as HttpError};
|
||||||
use http::uri::InvalidUriBytes;
|
use http::uri::InvalidUri;
|
||||||
use http_range::HttpRangeParseError;
|
use http_range::HttpRangeParseError;
|
||||||
use serde_json::error::Error as JsonError;
|
use serde_json::error::Error as JsonError;
|
||||||
pub use url::ParseError as UrlParseError;
|
pub use url::ParseError as UrlParseError;
|
||||||
@ -157,7 +156,7 @@ pub enum ParseError {
|
|||||||
Method,
|
Method,
|
||||||
/// An invalid `Uri`, such as `exam ple.domain`.
|
/// An invalid `Uri`, such as `exam ple.domain`.
|
||||||
#[fail(display="Uri error: {}", _0)]
|
#[fail(display="Uri error: {}", _0)]
|
||||||
Uri(InvalidUriBytes),
|
Uri(InvalidUri),
|
||||||
/// An invalid `HttpVersion`, such as `HTP/1.1`
|
/// An invalid `HttpVersion`, such as `HTP/1.1`
|
||||||
#[fail(display="Invalid HTTP version specified")]
|
#[fail(display="Invalid HTTP version specified")]
|
||||||
Version,
|
Version,
|
||||||
@ -198,6 +197,12 @@ impl From<IoError> for ParseError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<InvalidUri> for ParseError {
|
||||||
|
fn from(err: InvalidUri) -> ParseError {
|
||||||
|
ParseError::Uri(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Utf8Error> for ParseError {
|
impl From<Utf8Error> for ParseError {
|
||||||
fn from(err: Utf8Error) -> ParseError {
|
fn from(err: Utf8Error) -> ParseError {
|
||||||
ParseError::Utf8(err)
|
ParseError::Utf8(err)
|
||||||
|
@ -164,6 +164,8 @@ impl<T, H> Http1<T, H>
|
|||||||
},
|
},
|
||||||
Ok(Async::NotReady) => (),
|
Ok(Async::NotReady) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
trace!("Parse error: {:?}", err);
|
||||||
|
|
||||||
// notify all tasks
|
// notify all tasks
|
||||||
self.stream.disconnected();
|
self.stream.disconnected();
|
||||||
for entry in &mut self.tasks {
|
for entry in &mut self.tasks {
|
||||||
@ -293,9 +295,9 @@ impl<T, H> Http1<T, H>
|
|||||||
// deal with keep-alive
|
// deal with keep-alive
|
||||||
if self.tasks.is_empty() {
|
if self.tasks.is_empty() {
|
||||||
// no keep-alive situations
|
// no keep-alive situations
|
||||||
if (self.flags.contains(Flags::ERROR)
|
if self.flags.contains(Flags::ERROR) ||
|
||||||
|| !self.flags.contains(Flags::KEEPALIVE)
|
(!self.flags.contains(Flags::KEEPALIVE)
|
||||||
|| !self.settings.keep_alive_enabled()) &&
|
|| !self.settings.keep_alive_enabled()) &&
|
||||||
self.flags.contains(Flags::STARTED)
|
self.flags.contains(Flags::STARTED)
|
||||||
{
|
{
|
||||||
return Ok(Async::Ready(false))
|
return Ok(Async::Ready(false))
|
||||||
@ -502,10 +504,11 @@ impl Reader {
|
|||||||
let mut req = httparse::Request::new(&mut headers);
|
let mut req = httparse::Request::new(&mut headers);
|
||||||
match req.parse(b)? {
|
match req.parse(b)? {
|
||||||
httparse::Status::Complete(len) => {
|
httparse::Status::Complete(len) => {
|
||||||
let method = Method::from_bytes(req.method.unwrap().as_bytes())
|
let method = Method::from_bytes(
|
||||||
|
req.method.unwrap_or("").as_bytes())
|
||||||
.map_err(|_| ParseError::Method)?;
|
.map_err(|_| ParseError::Method)?;
|
||||||
let path = Uri::try_from(req.path.unwrap()).unwrap();
|
let path = Uri::try_from(req.path.unwrap())?;
|
||||||
let version = if req.version.unwrap() == 1 {
|
let version = if req.version.unwrap_or(1) == 1 {
|
||||||
Version::HTTP_11
|
Version::HTTP_11
|
||||||
} else {
|
} else {
|
||||||
Version::HTTP_10
|
Version::HTTP_10
|
||||||
|
Loading…
Reference in New Issue
Block a user