Skip to content

Commit

Permalink
fix: Consume complete message body even on error
Browse files Browse the repository at this point in the history
  • Loading branch information
gschulze committed Aug 16, 2024
1 parent f61fcbe commit b498c65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions actix-web/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Always remove port from return value of `ConnectionInfo::realip_remote_addr()` when handling IPv6 addresses. from the `Forwarded` header.
- The `UrlencodedError::ContentType` variant (relevant to the `Form` extractor) now uses the 415 (Media Type Unsupported) status code in it's `ResponseError` implementation.
- Apply `HttpServer::max_connection_rate()` setting when using rustls v0.22 or v0.23.
- Always consume complete HTTP message body, even on error

## 4.7.0

Expand Down
29 changes: 14 additions & 15 deletions actix-web/src/types/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,24 +417,23 @@ impl Future for HttpMessageBody {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();

if let Some(err) = this.err.take() {
return Poll::Ready(Err(err));
}
while let Some(chunk) = ready!(Pin::new(&mut this.stream).poll_next(cx)) {
if this.err.is_some() {
continue;
}

loop {
let res = ready!(Pin::new(&mut this.stream).poll_next(cx));
match res {
Some(chunk) => {
let chunk = chunk?;
if this.buf.len() + chunk.len() > this.limit {
return Poll::Ready(Err(PayloadError::Overflow));
} else {
this.buf.extend_from_slice(&chunk);
}
}
None => return Poll::Ready(Ok(this.buf.split().freeze())),
let chunk = chunk?;
if this.buf.len() + chunk.len() > this.limit {
this.err = Some(PayloadError::Overflow);
} else {
this.buf.extend_from_slice(&chunk);
}
}

Poll::Ready(match this.err.take() {
None => Ok(this.buf.split().freeze()),
Some(err) => Err(err),
})
}
}

Expand Down

0 comments on commit b498c65

Please sign in to comment.