Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume complete message body even on error #3454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions actix-web/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
Loading