Skip to content

Commit 2181642

Browse files
committed
fix: Consume complete message body even on error
1 parent 538c1be commit 2181642

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

actix-web/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Always remove port from return value of `ConnectionInfo::realip_remote_addr()` when handling IPv6 addresses. from the `Forwarded` header.
2222
- The `UrlencodedError::ContentType` variant (relevant to the `Form` extractor) now uses the 415 (Media Type Unsupported) status code in it's `ResponseError` implementation.
2323
- Apply `HttpServer::max_connection_rate()` setting when using rustls v0.22 or v0.23.
24+
- Always consume complete HTTP message body, even on error
2425

2526
## 4.7.0
2627

actix-web/src/types/payload.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -417,24 +417,23 @@ impl Future for HttpMessageBody {
417417
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
418418
let this = self.get_mut();
419419

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

424-
loop {
425-
let res = ready!(Pin::new(&mut this.stream).poll_next(cx));
426-
match res {
427-
Some(chunk) => {
428-
let chunk = chunk?;
429-
if this.buf.len() + chunk.len() > this.limit {
430-
return Poll::Ready(Err(PayloadError::Overflow));
431-
} else {
432-
this.buf.extend_from_slice(&chunk);
433-
}
434-
}
435-
None => return Poll::Ready(Ok(this.buf.split().freeze())),
425+
let chunk = chunk?;
426+
if this.buf.len() + chunk.len() > this.limit {
427+
this.err = Some(PayloadError::Overflow);
428+
} else {
429+
this.buf.extend_from_slice(&chunk);
436430
}
437431
}
432+
433+
Poll::Ready(match this.err.take() {
434+
None => Ok(this.buf.split().freeze()),
435+
Some(err) => Err(err),
436+
})
438437
}
439438
}
440439

0 commit comments

Comments
 (0)