1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 17:07:01 +02:00

support client request's async body

This commit is contained in:
Nikolay Kim
2018-02-19 22:48:27 -08:00
parent 3f95cce9e8
commit 03912d2089
8 changed files with 217 additions and 28 deletions

View File

@@ -111,6 +111,10 @@ impl HttpClientWriter {
buffer.reserve(256 + msg.headers().len() * AVERAGE_HEADER_SIZE);
}
if msg.upgrade() {
self.flags.insert(Flags::UPGRADE);
}
// status line
let _ = write!(buffer, "{} {} {:?}\r\n",
msg.method(), msg.uri().path(), msg.version());
@@ -145,10 +149,14 @@ impl HttpClientWriter {
Ok(())
}
pub fn write(&mut self, payload: &Binary) -> io::Result<WriterState> {
pub fn write(&mut self, payload: Binary) -> io::Result<WriterState> {
self.written += payload.len() as u64;
if !self.flags.contains(Flags::DISCONNECTED) {
self.buffer.extend_from_slice(payload.as_ref())
if self.flags.contains(Flags::UPGRADE) {
self.buffer.extend(payload);
} else {
self.encoder.write(payload)?;
}
}
if self.buffer.len() > self.high {
@@ -158,11 +166,14 @@ impl HttpClientWriter {
}
}
pub fn write_eof(&mut self) -> io::Result<WriterState> {
if self.buffer.len() > self.high {
Ok(WriterState::Pause)
pub fn write_eof(&mut self) -> io::Result<()> {
self.encoder.write_eof()?;
if !self.encoder.is_eof() {
Err(io::Error::new(io::ErrorKind::Other,
"Last payload item, but eof is not reached"))
} else {
Ok(WriterState::Done)
Ok(())
}
}