mirror of https://github.com/fafhrd91/actix-web
Merge 845534fc81
into 98d7d0b46b
This commit is contained in:
commit
4b55570272
|
@ -139,7 +139,7 @@ async fn h1_expect() {
|
||||||
|
|
||||||
// test expect would fail to continue
|
// test expect would fail to continue
|
||||||
let request = srv
|
let request = srv
|
||||||
.request(http::Method::GET, srv.url("/"))
|
.request(http::Method::POST, srv.url("/"))
|
||||||
.insert_header(("Expect", "100-continue"));
|
.insert_header(("Expect", "100-continue"));
|
||||||
|
|
||||||
let response = request.send_body("expect body").await.unwrap();
|
let response = request.send_body("expect body").await.unwrap();
|
||||||
|
@ -147,7 +147,7 @@ async fn h1_expect() {
|
||||||
|
|
||||||
// test expect would continue
|
// test expect would continue
|
||||||
let request = srv
|
let request = srv
|
||||||
.request(http::Method::GET, srv.url("/"))
|
.request(http::Method::POST, srv.url("/"))
|
||||||
.insert_header(("Expect", "100-continue"))
|
.insert_header(("Expect", "100-continue"))
|
||||||
.insert_header(("AUTH", "996"));
|
.insert_header(("AUTH", "996"));
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ async fn h2_body() -> io::Result<()> {
|
||||||
})
|
})
|
||||||
.await;
|
.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());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
let body = srv.load_body(response).await.unwrap();
|
let body = srv.load_body(response).await.unwrap();
|
||||||
|
|
|
@ -184,7 +184,7 @@ async fn h2_body1() -> io::Result<()> {
|
||||||
})
|
})
|
||||||
.await;
|
.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());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
let body = srv.load_body(response).await.unwrap();
|
let body = srv.load_body(response).await.unwrap();
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- `GET/HEAD/OPTIONS/TRACE` methods no longer send a request body on request.
|
||||||
|
|
||||||
## 3.7.0
|
## 3.7.0
|
||||||
|
|
||||||
- Update `brotli` dependency to `8`.
|
- Update `brotli` dependency to `8`.
|
||||||
|
|
|
@ -4,8 +4,12 @@ use std::{
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_http::body::{BodySize, BoxBody, MessageBody};
|
use actix_http::{
|
||||||
|
body::{BodySize, BoxBody, MessageBody},
|
||||||
|
RequestHead,
|
||||||
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use http::Method;
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
pin_project! {
|
pin_project! {
|
||||||
|
@ -75,11 +79,15 @@ where
|
||||||
/// Converts a [`MessageBody`] type into the best possible representation.
|
/// Converts a [`MessageBody`] type into the best possible representation.
|
||||||
///
|
///
|
||||||
/// Checks size for `None` and tries to convert to `Bytes`. Otherwise, uses the `Body` variant.
|
/// 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
|
where
|
||||||
B: MessageBody,
|
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;
|
return Self::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,16 +189,14 @@ impl RequestSender {
|
||||||
body: impl MessageBody + 'static,
|
body: impl MessageBody + 'static,
|
||||||
) -> SendClientRequest {
|
) -> SendClientRequest {
|
||||||
let req = match self {
|
let req = match self {
|
||||||
RequestSender::Owned(head) => ConnectRequest::Client(
|
RequestSender::Owned(head) => {
|
||||||
RequestHeadType::Owned(head),
|
let body = AnyBody::from_message_body(&head, body).into_boxed();
|
||||||
AnyBody::from_message_body(body).into_boxed(),
|
ConnectRequest::Client(RequestHeadType::Owned(head), body, addr)
|
||||||
addr,
|
}
|
||||||
),
|
RequestSender::Rc(head, extra_headers) => {
|
||||||
RequestSender::Rc(head, extra_headers) => ConnectRequest::Client(
|
let body = AnyBody::from_message_body(&head, body).into_boxed();
|
||||||
RequestHeadType::Rc(head, extra_headers),
|
ConnectRequest::Client(RequestHeadType::Rc(head, extra_headers), body, addr)
|
||||||
AnyBody::from_message_body(body).into_boxed(),
|
}
|
||||||
addr,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let fut = config.connector.call(req);
|
let fut = config.connector.call(req);
|
||||||
|
|
|
@ -62,7 +62,7 @@ async fn json() {
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv
|
let request = srv
|
||||||
.get("/")
|
.post("/")
|
||||||
.insert_header(("x-test", "111"))
|
.insert_header(("x-test", "111"))
|
||||||
.send_json(&"TEST".to_string());
|
.send_json(&"TEST".to_string());
|
||||||
let response = request.await.unwrap();
|
let response = request.await.unwrap();
|
||||||
|
|
Loading…
Reference in New Issue