Skip to content

Commit

Permalink
fix(server): prevent sending 100-continue if user drops request body (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar authored Feb 2, 2023
1 parent fc9f307 commit 499fe1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Bytes>::new())
Expand Down

0 comments on commit 499fe1f

Please sign in to comment.