From 499fe1f949895218c4fd2305a0eddaf24f1dd0a9 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 2 Feb 2023 09:12:57 -0500 Subject: [PATCH] fix(server): prevent sending 100-continue if user drops request body (#3137) --- src/proto/h1/conn.rs | 6 ++++++ tests/server.rs | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index 3250b7f3dc..b7c619683c 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -732,6 +732,12 @@ where /// If the read side can be cheaply drained, do so. Otherwise, close. pub(super) fn poll_drain_or_close_read(&mut self, cx: &mut task::Context<'_>) { + if let Reading::Continue(ref decoder) = self.state.reading { + // skip sending the 100-continue + // just move forward to a read, in case a tiny body was included + self.state.reading = Reading::Body(decoder.clone()); + } + let _ = self.poll_read_body(cx); // If still in Reading::Body, just give up diff --git a/tests/server.rs b/tests/server.rs index 68c53ce5c0..632ce4839a 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -965,9 +965,8 @@ async fn expect_continue_waits_for_body_poll() { service_fn(|req| { assert_eq!(req.headers()["expect"], "100-continue"); // But! We're never going to poll the body! + drop(req); TokioTimer.sleep(Duration::from_millis(50)).map(move |_| { - // Move and drop the req, so we don't auto-close - drop(req); Response::builder() .status(StatusCode::BAD_REQUEST) .body(Empty::::new())