fix: include content-length with bytes payload

This commit is contained in:
imgurbot12 2025-07-15 22:23:12 -07:00
parent b6ad483699
commit 83e521c933
No known key found for this signature in database
2 changed files with 6 additions and 2 deletions

View File

@ -2,6 +2,8 @@
## Unreleased ## Unreleased
- Update `TestRequest::set_payload` to generate "Content-Length" header
## 3.11.0 ## 3.11.0
- Update `brotli` dependency to `8`. - Update `brotli` dependency to `8`.

View File

@ -11,7 +11,7 @@ use std::{
use actix_codec::{AsyncRead, AsyncWrite, ReadBuf}; use actix_codec::{AsyncRead, AsyncWrite, ReadBuf};
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use http::{Method, Uri, Version}; use http::{header, Method, Uri, Version};
use crate::{ use crate::{
header::{HeaderMap, TryIntoHeaderPair}, header::{HeaderMap, TryIntoHeaderPair},
@ -100,7 +100,9 @@ impl TestRequest {
/// Set request payload. /// Set request payload.
pub fn set_payload(&mut self, data: impl Into<Bytes>) -> &mut Self { pub fn set_payload(&mut self, data: impl Into<Bytes>) -> &mut Self {
let mut payload = crate::h1::Payload::empty(); let mut payload = crate::h1::Payload::empty();
payload.unread_data(data.into()); let bytes = data.into();
self.insert_header((header::CONTENT_LENGTH, bytes.len()));
payload.unread_data(bytes);
parts(&mut self.0).payload = Some(payload.into()); parts(&mut self.0).payload = Some(payload.into());
self self
} }