Skip to content

Commit

Permalink
fix(server): prevent sending 100-continue if user drops request body (h…
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar authored and oddgrd committed Mar 7, 2023
1 parent 3c9a85a commit 3e2d9e2
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 @@ -748,6 +748,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 @@ -973,9 +973,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);
tokio::time::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(hyper::Body::empty())
Expand Down

0 comments on commit 3e2d9e2

Please sign in to comment.