Skip to content

Commit 612e983

Browse files
committed
fix(awc): some methods incorrectly send body & body-headers
1 parent aceff9d commit 612e983

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

awc/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- `GET/HEAD/OPTIONS/TRACE` methods no longer send a request body on request.
6+
57
## 3.7.0
68

79
- Update `brotli` dependency to `8`.

awc/src/any_body.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ use std::{
44
task::{Context, Poll},
55
};
66

7-
use actix_http::body::{BodySize, BoxBody, MessageBody};
7+
use actix_http::{
8+
body::{BodySize, BoxBody, MessageBody},
9+
RequestHead,
10+
};
811
use bytes::Bytes;
12+
use http::Method;
913
use pin_project_lite::pin_project;
1014

1115
pin_project! {
@@ -75,11 +79,15 @@ where
7579
/// Converts a [`MessageBody`] type into the best possible representation.
7680
///
7781
/// Checks size for `None` and tries to convert to `Bytes`. Otherwise, uses the `Body` variant.
78-
pub fn from_message_body(body: B) -> Self
82+
pub fn from_message_body(head: &RequestHead, body: B) -> Self
7983
where
8084
B: MessageBody,
8185
{
82-
if matches!(body.size(), BodySize::None) {
86+
if matches!(
87+
head.method,
88+
Method::GET | Method::HEAD | Method::OPTIONS | Method::TRACE
89+
) || matches!(body.size(), BodySize::None)
90+
{
8391
return Self::None;
8492
}
8593

awc/src/sender.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,14 @@ impl RequestSender {
189189
body: impl MessageBody + 'static,
190190
) -> SendClientRequest {
191191
let req = match self {
192-
RequestSender::Owned(head) => ConnectRequest::Client(
193-
RequestHeadType::Owned(head),
194-
AnyBody::from_message_body(body).into_boxed(),
195-
addr,
196-
),
197-
RequestSender::Rc(head, extra_headers) => ConnectRequest::Client(
198-
RequestHeadType::Rc(head, extra_headers),
199-
AnyBody::from_message_body(body).into_boxed(),
200-
addr,
201-
),
192+
RequestSender::Owned(head) => {
193+
let body = AnyBody::from_message_body(&head, body).into_boxed();
194+
ConnectRequest::Client(RequestHeadType::Owned(head), body, addr)
195+
}
196+
RequestSender::Rc(head, extra_headers) => {
197+
let body = AnyBody::from_message_body(&head, body).into_boxed();
198+
ConnectRequest::Client(RequestHeadType::Rc(head, extra_headers), body, addr)
199+
}
202200
};
203201

204202
let fut = config.connector.call(req);

0 commit comments

Comments
 (0)