1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 08:22:59 +01:00

flush encoder

This commit is contained in:
Nikolay Kim 2018-01-02 14:53:51 -08:00
parent fb2c78d9fc
commit 77ba1de305
4 changed files with 11 additions and 6 deletions

View File

@ -569,6 +569,7 @@ impl ContentEncoder {
match encoder.finish() {
Ok(mut writer) => {
writer.encode_eof();
*self = ContentEncoder::Identity(writer);
Ok(())
},
Err(err) => Err(err),
@ -578,6 +579,7 @@ impl ContentEncoder {
match encoder.finish() {
Ok(mut writer) => {
writer.encode_eof();
*self = ContentEncoder::Identity(writer);
Ok(())
},
Err(err) => Err(err),
@ -587,6 +589,7 @@ impl ContentEncoder {
match encoder.finish() {
Ok(mut writer) => {
writer.encode_eof();
*self = ContentEncoder::Identity(writer);
Ok(())
},
Err(err) => Err(err),
@ -594,6 +597,7 @@ impl ContentEncoder {
},
ContentEncoder::Identity(mut writer) => {
writer.encode_eof();
*self = ContentEncoder::Identity(writer);
Ok(())
}
}

View File

@ -95,7 +95,6 @@ impl<T: AsyncWrite> H1Writer<T> {
match self.stream.write(buffer.as_ref()) {
Ok(n) => {
buffer.split_to(n);
self.written += n as u64;
},
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
if buffer.len() > MAX_WRITE_BUFFER_SIZE {
@ -115,11 +114,7 @@ impl<T: AsyncWrite> Writer for H1Writer<T> {
#[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
fn written(&self) -> u64 {
if self.written > self.headers_size as u64 {
self.written - self.headers_size as u64
} else {
0
}
self.written
}
fn start(&mut self, req: &mut HttpMessage, msg: &mut HttpResponse)
@ -191,6 +186,7 @@ impl<T: AsyncWrite> Writer for H1Writer<T> {
}
if let Body::Binary(bytes) = body {
self.written = bytes.len() as u64;
self.encoder.write(bytes.as_ref())?;
} else {
msg.replace_body(body);
@ -199,6 +195,7 @@ impl<T: AsyncWrite> Writer for H1Writer<T> {
}
fn write(&mut self, payload: &[u8]) -> Result<WriterState, io::Error> {
self.written += payload.len() as u64;
if !self.flags.contains(Flags::DISCONNECTED) {
if self.flags.contains(Flags::STARTED) {
// TODO: add warning, write after EOF

View File

@ -167,6 +167,7 @@ impl Writer for H2Writer {
if let Body::Binary(bytes) = body {
self.flags.insert(Flags::EOF);
self.written = bytes.len() as u64;
self.encoder.write(bytes.as_ref())?;
if let Some(ref mut stream) = self.stream {
stream.reserve_capacity(cmp::min(self.encoder.len(), CHUNK_SIZE));
@ -179,6 +180,8 @@ impl Writer for H2Writer {
}
fn write(&mut self, payload: &[u8]) -> Result<WriterState, io::Error> {
self.written = payload.len() as u64;
if !self.flags.contains(Flags::DISCONNECTED) {
if self.flags.contains(Flags::STARTED) {
// TODO: add warning, write after EOF

View File

@ -677,6 +677,7 @@ impl<S, H> ProcessResponse<S, H> {
// response is completed
match self.iostate {
IOState::Done => {
io.write_eof();
self.resp.set_response_size(io.written());
Ok(FinishingMiddlewares::init(info, self.resp))
}