Skip to content

Commit 92443d7

Browse files
authored
fix(server): prevent sending 100-continue if user drops request body (#3138)
1 parent 4d89adc commit 92443d7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/proto/h1/conn.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,12 @@ where
748748

749749
/// If the read side can be cheaply drained, do so. Otherwise, close.
750750
pub(super) fn poll_drain_or_close_read(&mut self, cx: &mut task::Context<'_>) {
751+
if let Reading::Continue(ref decoder) = self.state.reading {
752+
// skip sending the 100-continue
753+
// just move forward to a read, in case a tiny body was included
754+
self.state.reading = Reading::Body(decoder.clone());
755+
}
756+
751757
let _ = self.poll_read_body(cx);
752758

753759
// If still in Reading::Body, just give up

tests/server.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,8 @@ async fn expect_continue_waits_for_body_poll() {
973973
service_fn(|req| {
974974
assert_eq!(req.headers()["expect"], "100-continue");
975975
// But! We're never going to poll the body!
976+
drop(req);
976977
tokio::time::sleep(Duration::from_millis(50)).map(move |_| {
977-
// Move and drop the req, so we don't auto-close
978-
drop(req);
979978
Response::builder()
980979
.status(StatusCode::BAD_REQUEST)
981980
.body(hyper::Body::empty())

0 commit comments

Comments
 (0)