mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
update tests; clippy warnings
This commit is contained in:
parent
6b2248ecdf
commit
8ab04b39df
@ -141,8 +141,8 @@ impl<A> HttpContext<A> where A: Actor<Context=Self> + Route {
|
||||
|
||||
/// Returns drain future
|
||||
pub fn drain(&mut self) -> Drain<A> {
|
||||
let fut = Rc::new(RefCell::new(DrainFut::new()));
|
||||
self.stream.push_back(Frame::Drain(fut.clone()));
|
||||
let fut = Rc::new(RefCell::new(DrainFut::default()));
|
||||
self.stream.push_back(Frame::Drain(Rc::clone(&fut)));
|
||||
self.modified = true;
|
||||
Drain{ a: PhantomData, inner: fut }
|
||||
}
|
||||
|
87
src/task.rs
87
src/task.rs
@ -66,14 +66,17 @@ pub struct DrainFut {
|
||||
task: Option<FutureTask>,
|
||||
}
|
||||
|
||||
impl DrainFut {
|
||||
impl Default for DrainFut {
|
||||
|
||||
pub fn new() -> DrainFut {
|
||||
fn default() -> DrainFut {
|
||||
DrainFut {
|
||||
drained: false,
|
||||
task: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DrainFut {
|
||||
|
||||
fn set(&mut self) {
|
||||
self.drained = true;
|
||||
@ -319,53 +322,51 @@ impl Task {
|
||||
// response is completed
|
||||
if self.frames.is_empty() && self.iostate.is_done() {
|
||||
return Ok(Async::Ready(self.state.is_done()));
|
||||
} else {
|
||||
if self.drain.is_empty() {
|
||||
// poll stream
|
||||
if self.state == TaskRunningState::Running {
|
||||
match self.poll() {
|
||||
Ok(Async::Ready(_)) => {
|
||||
self.state = TaskRunningState::Done;
|
||||
}
|
||||
Ok(Async::NotReady) => (),
|
||||
Err(_) => return Err(())
|
||||
} else if self.drain.is_empty() {
|
||||
// poll stream
|
||||
if self.state == TaskRunningState::Running {
|
||||
match self.poll() {
|
||||
Ok(Async::Ready(_)) => {
|
||||
self.state = TaskRunningState::Done;
|
||||
}
|
||||
Ok(Async::NotReady) => (),
|
||||
Err(_) => return Err(())
|
||||
}
|
||||
}
|
||||
|
||||
// use exiting frames
|
||||
while let Some(frame) = self.frames.pop_front() {
|
||||
trace!("IO Frame: {:?}", frame);
|
||||
match frame {
|
||||
Frame::Message(response) => {
|
||||
if !self.disconnected {
|
||||
self.prepare(req, response);
|
||||
// use exiting frames
|
||||
while let Some(frame) = self.frames.pop_front() {
|
||||
trace!("IO Frame: {:?}", frame);
|
||||
match frame {
|
||||
Frame::Message(response) => {
|
||||
if !self.disconnected {
|
||||
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 {
|
||||
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(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
|
||||
},
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ mod tests {
|
||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||
Version::HTTP_11, HeaderMap::new(), String::new());
|
||||
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"),
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ mod tests {
|
||||
let req = HttpRequest::new(Method::GET, "/".to_owned(),
|
||||
Version::HTTP_11, headers, String::new());
|
||||
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"),
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ fn test_request_query() {
|
||||
|
||||
assert_eq!(req.query_string(), "id=test");
|
||||
let query = req.query();
|
||||
assert_eq!(query.get("id").unwrap(), "test");
|
||||
assert_eq!(&query["id"], "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user