Skip to content
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
4 changes: 2 additions & 2 deletions actix-http/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ async fn h1_expect() {

// test expect would fail to continue
let request = srv
.request(http::Method::GET, srv.url("/"))
.request(http::Method::POST, srv.url("/"))
.insert_header(("Expect", "100-continue"));

let response = request.send_body("expect body").await.unwrap();
assert_eq!(response.status(), StatusCode::EXPECTATION_FAILED);

// test expect would continue
let request = srv
.request(http::Method::GET, srv.url("/"))
.request(http::Method::POST, srv.url("/"))
.insert_header(("Expect", "100-continue"))
.insert_header(("AUTH", "996"));

Expand Down
2 changes: 1 addition & 1 deletion actix-http/tests/test_openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn h2_body() -> io::Result<()> {
})
.await;

let response = srv.sget("/").send_body(data.clone()).await.unwrap();
let response = srv.spost("/").send_body(data.clone()).await.unwrap();
assert!(response.status().is_success());

let body = srv.load_body(response).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion actix-http/tests/test_rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async fn h2_body1() -> io::Result<()> {
})
.await;

let response = srv.sget("/").send_body(data.clone()).await.unwrap();
let response = srv.spost("/").send_body(data.clone()).await.unwrap();
assert!(response.status().is_success());

let body = srv.load_body(response).await.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions awc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
14 changes: 11 additions & 3 deletions awc/src/any_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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;
}

Expand Down
18 changes: 8 additions & 10 deletions awc/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion awc/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn json() {
});

let request = srv
.get("/")
.post("/")
.insert_header(("x-test", "111"))
.send_json(&"TEST".to_string());
let response = request.await.unwrap();
Expand Down
Loading