mirror of
https://github.com/actix/actix-web.git
synced 2024-12-23 00:26:34 +00:00
return error on write zero bytes
This commit is contained in:
parent
71b4c07ea4
commit
6c709b33cc
3 changed files with 17 additions and 23 deletions
|
@ -1,13 +1,13 @@
|
|||
# Changes
|
||||
|
||||
## 0.4.6 (2018-03-09)
|
||||
## 0.4.6 (2018-03-10)
|
||||
|
||||
* Fix client cookie handling
|
||||
|
||||
* Fix CORS middleware #117
|
||||
|
||||
* Fix json content type detection
|
||||
|
||||
* Fix CORS middleware #117
|
||||
|
||||
* Optimize websockets stream support
|
||||
|
||||
|
||||
|
|
|
@ -196,8 +196,8 @@ mod tests {
|
|||
|
||||
let mut req = HttpRequest::default();
|
||||
req.headers_mut().insert(header::CONTENT_TYPE,
|
||||
header::HeaderValue::from_static("application/json"));
|
||||
let mut json = req.json::<MyObject>().content_type("text/json");
|
||||
header::HeaderValue::from_static("application/text"));
|
||||
let mut json = req.json::<MyObject>();
|
||||
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::ContentType);
|
||||
|
||||
let mut req = HttpRequest::default();
|
||||
|
|
|
@ -68,22 +68,22 @@ impl<T: AsyncWrite> H1Writer<T> {
|
|||
self.flags.contains(Flags::KEEPALIVE) && !self.flags.contains(Flags::UPGRADE)
|
||||
}
|
||||
|
||||
fn write_data(&mut self, data: &[u8]) -> io::Result<(usize, bool)> {
|
||||
fn write_data(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||
let mut written = 0;
|
||||
while written < data.len() {
|
||||
match self.stream.write(&data[written..]) {
|
||||
Ok(0) => {
|
||||
self.disconnected();
|
||||
return Ok((0, true));
|
||||
return Err(io::Error::new(io::ErrorKind::WriteZero, ""))
|
||||
},
|
||||
Ok(n) => written += n,
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
return Ok((written, false))
|
||||
return Ok(written)
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
Ok((written, false))
|
||||
Ok(written)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,12 +211,10 @@ impl<T: AsyncWrite> Writer for H1Writer<T> {
|
|||
// shortcut for upgraded connection
|
||||
if self.flags.contains(Flags::UPGRADE) {
|
||||
if self.buffer.is_empty() {
|
||||
match self.write_data(payload.as_ref())? {
|
||||
(_, true) => return Ok(WriterState::Done),
|
||||
(n, false) => if payload.len() < n {
|
||||
self.buffer.extend_from_slice(&payload.as_ref()[n..]);
|
||||
return Ok(WriterState::Done);
|
||||
}
|
||||
let n = self.write_data(payload.as_ref())?;
|
||||
if payload.len() < n {
|
||||
self.buffer.extend_from_slice(&payload.as_ref()[n..]);
|
||||
return Ok(WriterState::Done);
|
||||
}
|
||||
} else {
|
||||
self.buffer.extend(payload);
|
||||
|
@ -255,14 +253,10 @@ impl<T: AsyncWrite> Writer for H1Writer<T> {
|
|||
fn poll_completed(&mut self, shutdown: bool) -> Poll<(), io::Error> {
|
||||
if !self.buffer.is_empty() {
|
||||
let buf: &[u8] = unsafe{mem::transmute(self.buffer.as_ref())};
|
||||
match self.write_data(buf)? {
|
||||
(_, true) => (),
|
||||
(n, false) => {
|
||||
let _ = self.buffer.split_to(n);
|
||||
if self.buffer.len() > self.buffer_capacity {
|
||||
return Ok(Async::NotReady)
|
||||
}
|
||||
}
|
||||
let written = self.write_data(buf)?;
|
||||
let _ = self.buffer.split_to(written);
|
||||
if self.buffer.len() > self.buffer_capacity {
|
||||
return Ok(Async::NotReady)
|
||||
}
|
||||
}
|
||||
if shutdown {
|
||||
|
|
Loading…
Reference in a new issue