fix(awc): some methods incorrectly send body & body-headers

This commit is contained in:
imgurbot12 2025-07-30 20:53:18 -07:00
parent aceff9d13f
commit 612e983576
No known key found for this signature in database
3 changed files with 21 additions and 13 deletions

View File

@ -2,6 +2,8 @@
## Unreleased
- `GET/HEAD/OPTIONS/TRACE` methods no longer send a request body on request.
## 3.7.0
- Update `brotli` dependency to `8`.

View File

@ -4,8 +4,12 @@ use std::{
task::{Context, Poll},
};
use actix_http::body::{BodySize, BoxBody, MessageBody};
use actix_http::{
body::{BodySize, BoxBody, MessageBody},
RequestHead,
};
use bytes::Bytes;
use http::Method;
use pin_project_lite::pin_project;
pin_project! {
@ -75,11 +79,15 @@ where
/// Converts a [`MessageBody`] type into the best possible representation.
///
/// Checks size for `None` and tries to convert to `Bytes`. Otherwise, uses the `Body` variant.
pub fn from_message_body(body: B) -> Self
pub fn from_message_body(head: &RequestHead, body: B) -> Self
where
B: MessageBody,
{
if matches!(body.size(), BodySize::None) {
if matches!(
head.method,
Method::GET | Method::HEAD | Method::OPTIONS | Method::TRACE
) || matches!(body.size(), BodySize::None)
{
return Self::None;
}

View File

@ -189,16 +189,14 @@ impl RequestSender {
body: impl MessageBody + 'static,
) -> SendClientRequest {
let req = match self {
RequestSender::Owned(head) => ConnectRequest::Client(
RequestHeadType::Owned(head),
AnyBody::from_message_body(body).into_boxed(),
addr,
),
RequestSender::Rc(head, extra_headers) => ConnectRequest::Client(
RequestHeadType::Rc(head, extra_headers),
AnyBody::from_message_body(body).into_boxed(),
addr,
),
RequestSender::Owned(head) => {
let body = AnyBody::from_message_body(&head, body).into_boxed();
ConnectRequest::Client(RequestHeadType::Owned(head), body, addr)
}
RequestSender::Rc(head, extra_headers) => {
let body = AnyBody::from_message_body(&head, body).into_boxed();
ConnectRequest::Client(RequestHeadType::Rc(head, extra_headers), body, addr)
}
};
let fut = config.connector.call(req);