From 83e521c9332fb5fbd6c5eef7c97e34883a9e5c3e Mon Sep 17 00:00:00 2001 From: imgurbot12 Date: Tue, 15 Jul 2025 22:23:12 -0700 Subject: [PATCH] fix: include content-length with bytes payload --- actix-http/CHANGES.md | 2 ++ actix-http/src/test.rs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index dc0a02730..715156d5e 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Update `TestRequest::set_payload` to generate "Content-Length" header + ## 3.11.0 - Update `brotli` dependency to `8`. diff --git a/actix-http/src/test.rs b/actix-http/src/test.rs index dfa9a86c9..84a6d731b 100644 --- a/actix-http/src/test.rs +++ b/actix-http/src/test.rs @@ -11,7 +11,7 @@ use std::{ use actix_codec::{AsyncRead, AsyncWrite, ReadBuf}; use bytes::{Bytes, BytesMut}; -use http::{Method, Uri, Version}; +use http::{header, Method, Uri, Version}; use crate::{ header::{HeaderMap, TryIntoHeaderPair}, @@ -100,7 +100,9 @@ impl TestRequest { /// Set request payload. pub fn set_payload(&mut self, data: impl Into) -> &mut Self { 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()); self }