mirror of
https://github.com/actix/actix-web.git
synced 2024-11-20 08:31:09 +00:00
update tests; clippy warnings
This commit is contained in:
parent
6b2248ecdf
commit
8ab04b39df
4 changed files with 49 additions and 48 deletions
|
@ -141,8 +141,8 @@ impl<A> HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||||
|
|
||||||
/// Returns drain future
|
/// Returns drain future
|
||||||
pub fn drain(&mut self) -> Drain<A> {
|
pub fn drain(&mut self) -> Drain<A> {
|
||||||
let fut = Rc::new(RefCell::new(DrainFut::new()));
|
let fut = Rc::new(RefCell::new(DrainFut::default()));
|
||||||
self.stream.push_back(Frame::Drain(fut.clone()));
|
self.stream.push_back(Frame::Drain(Rc::clone(&fut)));
|
||||||
self.modified = true;
|
self.modified = true;
|
||||||
Drain{ a: PhantomData, inner: fut }
|
Drain{ a: PhantomData, inner: fut }
|
||||||
}
|
}
|
||||||
|
|
87
src/task.rs
87
src/task.rs
|
@ -66,14 +66,17 @@ pub struct DrainFut {
|
||||||
task: Option<FutureTask>,
|
task: Option<FutureTask>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrainFut {
|
impl Default for DrainFut {
|
||||||
|
|
||||||
pub fn new() -> DrainFut {
|
fn default() -> DrainFut {
|
||||||
DrainFut {
|
DrainFut {
|
||||||
drained: false,
|
drained: false,
|
||||||
task: None,
|
task: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DrainFut {
|
||||||
|
|
||||||
fn set(&mut self) {
|
fn set(&mut self) {
|
||||||
self.drained = true;
|
self.drained = true;
|
||||||
|
@ -319,53 +322,51 @@ impl Task {
|
||||||
// response is completed
|
// response is completed
|
||||||
if self.frames.is_empty() && self.iostate.is_done() {
|
if self.frames.is_empty() && self.iostate.is_done() {
|
||||||
return Ok(Async::Ready(self.state.is_done()));
|
return Ok(Async::Ready(self.state.is_done()));
|
||||||
} else {
|
} else if self.drain.is_empty() {
|
||||||
if self.drain.is_empty() {
|
// poll stream
|
||||||
// poll stream
|
if self.state == TaskRunningState::Running {
|
||||||
if self.state == TaskRunningState::Running {
|
match self.poll() {
|
||||||
match self.poll() {
|
Ok(Async::Ready(_)) => {
|
||||||
Ok(Async::Ready(_)) => {
|
self.state = TaskRunningState::Done;
|
||||||
self.state = TaskRunningState::Done;
|
|
||||||
}
|
|
||||||
Ok(Async::NotReady) => (),
|
|
||||||
Err(_) => return Err(())
|
|
||||||
}
|
}
|
||||||
|
Ok(Async::NotReady) => (),
|
||||||
|
Err(_) => return Err(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// use exiting frames
|
// use exiting frames
|
||||||
while let Some(frame) = self.frames.pop_front() {
|
while let Some(frame) = self.frames.pop_front() {
|
||||||
trace!("IO Frame: {:?}", frame);
|
trace!("IO Frame: {:?}", frame);
|
||||||
match frame {
|
match frame {
|
||||||
Frame::Message(response) => {
|
Frame::Message(response) => {
|
||||||
if !self.disconnected {
|
if !self.disconnected {
|
||||||
self.prepare(req, response);
|
self.prepare(req, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Frame::Payload(Some(chunk)) => {
|
||||||
|
if !self.disconnected {
|
||||||
|
if self.prepared.is_some() {
|
||||||
|
// TODO: add warning, write after EOF
|
||||||
|
self.encoder.encode(&mut self.buffer, chunk.as_ref());
|
||||||
|
} else {
|
||||||
|
// might be response for EXCEPT
|
||||||
|
self.buffer.extend_from_slice(chunk.as_ref())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Frame::Payload(Some(chunk)) => {
|
},
|
||||||
if !self.disconnected {
|
Frame::Payload(None) => {
|
||||||
if self.prepared.is_some() {
|
if !self.disconnected &&
|
||||||
// TODO: add warning, write after EOF
|
!self.encoder.encode(&mut self.buffer, [].as_ref())
|
||||||
self.encoder.encode(&mut self.buffer, chunk.as_ref());
|
{
|
||||||
} else {
|
// TODO: add error "not eof""
|
||||||
// might be response for EXCEPT
|
debug!("last payload item, but it is not EOF ");
|
||||||
self.buffer.extend_from_slice(chunk.as_ref())
|
return Err(())
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Frame::Payload(None) => {
|
|
||||||
if !self.disconnected &&
|
|
||||||
!self.encoder.encode(&mut self.buffer, [].as_ref())
|
|
||||||
{
|
|
||||||
// TODO: add error "not eof""
|
|
||||||
debug!("last payload item, but it is not EOF ");
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
break
|
|
||||||
},
|
|
||||||
Frame::Drain(fut) => {
|
|
||||||
self.drain.push(fut);
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
},
|
||||||
|
Frame::Drain(fut) => {
|
||||||
|
self.drain.push(fut);
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,7 +344,7 @@ mod tests {
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, HeaderMap::new(), String::new());
|
Version::HTTP_11, HeaderMap::new(), String::new());
|
||||||
match handshake(&req) {
|
match handshake(&req) {
|
||||||
Err(err) => assert_eq!(err.status(), StatusCode::METHOD_NOT_ALLOWED),
|
Err(err) => assert_eq!(err.status(), StatusCode::BAD_REQUEST),
|
||||||
_ => panic!("should not happen"),
|
_ => panic!("should not happen"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ mod tests {
|
||||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||||
Version::HTTP_11, headers, String::new());
|
Version::HTTP_11, headers, String::new());
|
||||||
match handshake(&req) {
|
match handshake(&req) {
|
||||||
Err(err) => assert_eq!(err.status(), StatusCode::METHOD_NOT_ALLOWED),
|
Err(err) => assert_eq!(err.status(), StatusCode::BAD_REQUEST),
|
||||||
_ => panic!("should not happen"),
|
_ => panic!("should not happen"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ fn test_request_query() {
|
||||||
|
|
||||||
assert_eq!(req.query_string(), "id=test");
|
assert_eq!(req.query_string(), "id=test");
|
||||||
let query = req.query();
|
let query = req.query();
|
||||||
assert_eq!(query.get("id").unwrap(), "test");
|
assert_eq!(&query["id"], "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue