mirror of https://github.com/fafhrd91/actix-web
refactor: use Payload::from internally
This commit is contained in:
parent
e8351cc3aa
commit
c6e7ebd185
|
@ -238,7 +238,7 @@ where
|
||||||
match res {
|
match res {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
let fallback = bytes.clone();
|
let fallback = bytes.clone();
|
||||||
let left = L::from_request(this.req, &mut payload_from_bytes(bytes));
|
let left = L::from_request(this.req, &mut dev::Payload::from(bytes));
|
||||||
EitherExtractState::Left { left, fallback }
|
EitherExtractState::Left { left, fallback }
|
||||||
}
|
}
|
||||||
Err(err) => break Err(EitherExtractError::Bytes(err)),
|
Err(err) => break Err(EitherExtractError::Bytes(err)),
|
||||||
|
@ -251,7 +251,7 @@ where
|
||||||
Err(left_err) => {
|
Err(left_err) => {
|
||||||
let right = R::from_request(
|
let right = R::from_request(
|
||||||
this.req,
|
this.req,
|
||||||
&mut payload_from_bytes(mem::take(fallback)),
|
&mut dev::Payload::from(mem::take(fallback)),
|
||||||
);
|
);
|
||||||
EitherExtractState::Right {
|
EitherExtractState::Right {
|
||||||
left_err: Some(left_err),
|
left_err: Some(left_err),
|
||||||
|
@ -276,12 +276,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn payload_from_bytes(bytes: Bytes) -> dev::Payload {
|
|
||||||
let (_, mut h1_payload) = actix_http::h1::Payload::create(true);
|
|
||||||
h1_payload.unread_data(bytes);
|
|
||||||
dev::Payload::from(h1_payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -98,7 +98,7 @@ dangerous-h2c = []
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.5"
|
actix-codec = "0.5"
|
||||||
actix-service = "2"
|
actix-service = "2"
|
||||||
actix-http = { version = "3.7", features = ["http2", "ws"] }
|
actix-http = { version = "3.10", features = ["http2", "ws"] }
|
||||||
actix-rt = { version = "2.1", default-features = false }
|
actix-rt = { version = "2.1", default-features = false }
|
||||||
actix-tls = { version = "3.4", features = ["connect", "uri"] }
|
actix-tls = { version = "3.4", features = ["connect", "uri"] }
|
||||||
actix-utils = "3"
|
actix-utils = "3"
|
||||||
|
|
|
@ -65,9 +65,7 @@ impl TestResponse {
|
||||||
|
|
||||||
/// Set response's payload
|
/// Set response's payload
|
||||||
pub fn set_payload<B: Into<Bytes>>(mut self, data: B) -> Self {
|
pub fn set_payload<B: Into<Bytes>>(mut self, data: B) -> Self {
|
||||||
let (_, mut payload) = h1::Payload::create(true);
|
self.payload = Some(Payload::from(data.into()));
|
||||||
payload.unread_data(data.into());
|
|
||||||
self.payload = Some(payload.into());
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue