refactor: use Payload::from internally

This commit is contained in:
Rob Ede 2025-03-10 04:23:03 +00:00
parent e8351cc3aa
commit c6e7ebd185
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 4 additions and 12 deletions

View File

@ -238,7 +238,7 @@ where
match res {
Ok(bytes) => {
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 }
}
Err(err) => break Err(EitherExtractError::Bytes(err)),
@ -251,7 +251,7 @@ where
Err(left_err) => {
let right = R::from_request(
this.req,
&mut payload_from_bytes(mem::take(fallback)),
&mut dev::Payload::from(mem::take(fallback)),
);
EitherExtractState::Right {
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)]
mod tests {
use serde::{Deserialize, Serialize};

View File

@ -98,7 +98,7 @@ dangerous-h2c = []
[dependencies]
actix-codec = "0.5"
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-tls = { version = "3.4", features = ["connect", "uri"] }
actix-utils = "3"

View File

@ -65,9 +65,7 @@ impl TestResponse {
/// Set response's payload
pub fn set_payload<B: Into<Bytes>>(mut self, data: B) -> Self {
let (_, mut payload) = h1::Payload::create(true);
payload.unread_data(data.into());
self.payload = Some(payload.into());
self.payload = Some(Payload::from(data.into()));
self
}