mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
Send response to inform client of error (#515)
This commit is contained in:
parent
f40153fca4
commit
0dc96658f2
@ -1,5 +1,11 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.7.9] - 2018-09-x
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* HTTP1 decoding errors are reported to the client. #512
|
||||||
|
|
||||||
## [0.7.8] - 2018-09-17
|
## [0.7.8] - 2018-09-17
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
//! Payload stream
|
//! Payload stream
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures::task::{current as current_task, Task};
|
use futures::task::Task;
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use futures::task::current as current_task;
|
||||||
use futures::{Async, Poll, Stream};
|
use futures::{Async, Poll, Stream};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
@ -373,6 +373,16 @@ where
|
|||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn push_response_entry(&mut self, status: StatusCode) {
|
||||||
|
self.tasks.push_back(Entry {
|
||||||
|
pipe: EntryPipe::Error(ServerError::err(
|
||||||
|
Version::HTTP_11,
|
||||||
|
status,
|
||||||
|
)),
|
||||||
|
flags: EntryFlags::empty(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(&mut self) {
|
pub fn parse(&mut self) {
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
match self.decoder.decode(&mut self.buf, &self.settings) {
|
match self.decoder.decode(&mut self.buf, &self.settings) {
|
||||||
@ -439,13 +449,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handler is not found
|
// handler is not found
|
||||||
self.tasks.push_back(Entry {
|
self.push_response_entry(StatusCode::NOT_FOUND);
|
||||||
pipe: EntryPipe::Error(ServerError::err(
|
|
||||||
Version::HTTP_11,
|
|
||||||
StatusCode::NOT_FOUND,
|
|
||||||
)),
|
|
||||||
flags: EntryFlags::empty(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Ok(Some(Message::Chunk(chunk))) => {
|
Ok(Some(Message::Chunk(chunk))) => {
|
||||||
if let Some(ref mut payload) = self.payload {
|
if let Some(ref mut payload) = self.payload {
|
||||||
@ -453,6 +457,7 @@ where
|
|||||||
} else {
|
} else {
|
||||||
error!("Internal server error: unexpected payload chunk");
|
error!("Internal server error: unexpected payload chunk");
|
||||||
self.flags.insert(Flags::ERROR);
|
self.flags.insert(Flags::ERROR);
|
||||||
|
self.push_response_entry(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,6 +467,7 @@ where
|
|||||||
} else {
|
} else {
|
||||||
error!("Internal server error: unexpected eof");
|
error!("Internal server error: unexpected eof");
|
||||||
self.flags.insert(Flags::ERROR);
|
self.flags.insert(Flags::ERROR);
|
||||||
|
self.push_response_entry(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -482,6 +488,9 @@ where
|
|||||||
};
|
};
|
||||||
payload.set_error(e);
|
payload.set_error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Malformed requests should be responded with 400
|
||||||
|
self.push_response_entry(StatusCode::BAD_REQUEST);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -660,6 +669,7 @@ mod tests {
|
|||||||
h1.poll_io();
|
h1.poll_io();
|
||||||
h1.poll_io();
|
h1.poll_io();
|
||||||
assert!(h1.flags.contains(Flags::ERROR));
|
assert!(h1.flags.contains(Flags::ERROR));
|
||||||
|
assert_eq!(h1.tasks.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -11,6 +11,7 @@ extern crate rand;
|
|||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
extern crate tokio_reactor;
|
extern crate tokio_reactor;
|
||||||
extern crate tokio_tcp;
|
extern crate tokio_tcp;
|
||||||
|
extern crate tokio_current_thread as current_thread;
|
||||||
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -28,7 +29,6 @@ use h2::client as h2client;
|
|||||||
use modhttp::Request;
|
use modhttp::Request;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use tokio::executor::current_thread;
|
|
||||||
use tokio::runtime::current_thread::Runtime;
|
use tokio::runtime::current_thread::Runtime;
|
||||||
use tokio_tcp::TcpStream;
|
use tokio_tcp::TcpStream;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user