refactor(http): Dedup code in connection state update.
This commit is contained in:
@@ -692,51 +692,32 @@ impl<H: MessageHandler<T>, T: Transport> State<H, T> {
|
||||
Reading::KeepAlive => http1.reading,
|
||||
_ => Reading::Closed,
|
||||
};
|
||||
let writing = match http1.writing {
|
||||
Writing::Wait(encoder) |
|
||||
Writing::Ready(encoder) => {
|
||||
if encoder.is_eof() {
|
||||
if http1.keep_alive {
|
||||
Writing::KeepAlive
|
||||
} else {
|
||||
Writing::Closed
|
||||
}
|
||||
} else if let Some(buf) = encoder.finish() {
|
||||
Writing::Chunk(Chunk {
|
||||
buf: buf.bytes,
|
||||
pos: buf.pos,
|
||||
next: (h1::Encoder::length(0), Next::end())
|
||||
})
|
||||
} else {
|
||||
Writing::Closed
|
||||
}
|
||||
}
|
||||
let mut writing = Writing::Closed;
|
||||
let encoder = match http1.writing {
|
||||
Writing::Wait(enc) | Writing::Ready(enc) => Some(enc),
|
||||
Writing::Chunk(mut chunk) => {
|
||||
if chunk.is_written() {
|
||||
let encoder = chunk.next.0;
|
||||
//TODO: de-dupe this code and from Writing::Ready
|
||||
if encoder.is_eof() {
|
||||
if http1.keep_alive {
|
||||
Writing::KeepAlive
|
||||
Some(chunk.next.0)
|
||||
} else {
|
||||
Writing::Closed
|
||||
chunk.next.1 = next;
|
||||
writing = Writing::Chunk(chunk);
|
||||
None
|
||||
}
|
||||
},
|
||||
_ => return // Keep State::Closed.
|
||||
};
|
||||
if let Some(encoder) = encoder {
|
||||
if encoder.is_eof() {
|
||||
if http1.keep_alive { writing = Writing::KeepAlive }
|
||||
} else if let Some(buf) = encoder.finish() {
|
||||
Writing::Chunk(Chunk {
|
||||
writing = Writing::Chunk(Chunk {
|
||||
buf: buf.bytes,
|
||||
pos: buf.pos,
|
||||
next: (h1::Encoder::length(0), Next::end())
|
||||
})
|
||||
} else {
|
||||
Writing::Closed
|
||||
}
|
||||
} else {
|
||||
chunk.next.1 = next;
|
||||
Writing::Chunk(chunk)
|
||||
}
|
||||
},
|
||||
_ => return, // Keep State::Closed.
|
||||
};
|
||||
|
||||
match (reading, writing) {
|
||||
(Reading::KeepAlive, Writing::KeepAlive) => {
|
||||
let next = factory.keep_alive_interest();
|
||||
|
||||
Reference in New Issue
Block a user