mirror of
https://github.com/actix/actix-web.git
synced 2024-12-23 08:36: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
|
# Changes
|
||||||
|
|
||||||
## 0.4.6 (2018-03-09)
|
## 0.4.6 (2018-03-10)
|
||||||
|
|
||||||
* Fix client cookie handling
|
* Fix client cookie handling
|
||||||
|
|
||||||
* Fix CORS middleware #117
|
|
||||||
|
|
||||||
* Fix json content type detection
|
* Fix json content type detection
|
||||||
|
|
||||||
|
* Fix CORS middleware #117
|
||||||
|
|
||||||
* Optimize websockets stream support
|
* Optimize websockets stream support
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -196,8 +196,8 @@ mod tests {
|
||||||
|
|
||||||
let mut req = HttpRequest::default();
|
let mut req = HttpRequest::default();
|
||||||
req.headers_mut().insert(header::CONTENT_TYPE,
|
req.headers_mut().insert(header::CONTENT_TYPE,
|
||||||
header::HeaderValue::from_static("application/json"));
|
header::HeaderValue::from_static("application/text"));
|
||||||
let mut json = req.json::<MyObject>().content_type("text/json");
|
let mut json = req.json::<MyObject>();
|
||||||
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::ContentType);
|
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::ContentType);
|
||||||
|
|
||||||
let mut req = HttpRequest::default();
|
let mut req = HttpRequest::default();
|
||||||
|
|
|
@ -68,22 +68,22 @@ impl<T: AsyncWrite> H1Writer<T> {
|
||||||
self.flags.contains(Flags::KEEPALIVE) && !self.flags.contains(Flags::UPGRADE)
|
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;
|
let mut written = 0;
|
||||||
while written < data.len() {
|
while written < data.len() {
|
||||||
match self.stream.write(&data[written..]) {
|
match self.stream.write(&data[written..]) {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
self.disconnected();
|
self.disconnected();
|
||||||
return Ok((0, true));
|
return Err(io::Error::new(io::ErrorKind::WriteZero, ""))
|
||||||
},
|
},
|
||||||
Ok(n) => written += n,
|
Ok(n) => written += n,
|
||||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
return Ok((written, false))
|
return Ok(written)
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err),
|
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
|
// shortcut for upgraded connection
|
||||||
if self.flags.contains(Flags::UPGRADE) {
|
if self.flags.contains(Flags::UPGRADE) {
|
||||||
if self.buffer.is_empty() {
|
if self.buffer.is_empty() {
|
||||||
match self.write_data(payload.as_ref())? {
|
let n = self.write_data(payload.as_ref())?;
|
||||||
(_, true) => return Ok(WriterState::Done),
|
if payload.len() < n {
|
||||||
(n, false) => if payload.len() < n {
|
self.buffer.extend_from_slice(&payload.as_ref()[n..]);
|
||||||
self.buffer.extend_from_slice(&payload.as_ref()[n..]);
|
return Ok(WriterState::Done);
|
||||||
return Ok(WriterState::Done);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.buffer.extend(payload);
|
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> {
|
fn poll_completed(&mut self, shutdown: bool) -> Poll<(), io::Error> {
|
||||||
if !self.buffer.is_empty() {
|
if !self.buffer.is_empty() {
|
||||||
let buf: &[u8] = unsafe{mem::transmute(self.buffer.as_ref())};
|
let buf: &[u8] = unsafe{mem::transmute(self.buffer.as_ref())};
|
||||||
match self.write_data(buf)? {
|
let written = self.write_data(buf)?;
|
||||||
(_, true) => (),
|
let _ = self.buffer.split_to(written);
|
||||||
(n, false) => {
|
if self.buffer.len() > self.buffer_capacity {
|
||||||
let _ = self.buffer.split_to(n);
|
return Ok(Async::NotReady)
|
||||||
if self.buffer.len() > self.buffer_capacity {
|
|
||||||
return Ok(Async::NotReady)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if shutdown {
|
if shutdown {
|
||||||
|
|
Loading…
Reference in a new issue