Skip to content

Commit 499fe1f

Browse files
authoredFeb 2, 2023
fix(server): prevent sending 100-continue if user drops request body (#3137)
1 parent fc9f307 commit 499fe1f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
 

‎src/proto/h1/conn.rs

+6
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,12 @@ where
732732

733733
/// If the read side can be cheaply drained, do so. Otherwise, close.
734734
pub(super) fn poll_drain_or_close_read(&mut self, cx: &mut task::Context<'_>) {
735+
if let Reading::Continue(ref decoder) = self.state.reading {
736+
// skip sending the 100-continue
737+
// just move forward to a read, in case a tiny body was included
738+
self.state.reading = Reading::Body(decoder.clone());
739+
}
740+
735741
let _ = self.poll_read_body(cx);
736742

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

‎tests/server.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,8 @@ async fn expect_continue_waits_for_body_poll() {
965965
service_fn(|req| {
966966
assert_eq!(req.headers()["expect"], "100-continue");
967967
// But! We're never going to poll the body!
968+
drop(req);
968969
TokioTimer.sleep(Duration::from_millis(50)).map(move |_| {
969-
// Move and drop the req, so we don't auto-close
970-
drop(req);
971970
Response::builder()
972971
.status(StatusCode::BAD_REQUEST)
973972
.body(Empty::<Bytes>::new())

0 commit comments

Comments
 (0)
Please sign in to comment.