mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 08:57:00 +02:00
fix: include content-length with bytes payload (#3695)
* fix: include content-length with bytes payload * chore: json unit-test patch * Update doc comment --------- Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Update `TestRequest::set_payload` to generate "Content-Length" header
|
||||
- Malformed websocket frames are now gracefully rejected.
|
||||
|
||||
## 3.11.0
|
||||
|
@@ -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},
|
||||
@@ -98,9 +98,13 @@ impl TestRequest {
|
||||
}
|
||||
|
||||
/// Set request payload.
|
||||
///
|
||||
/// This sets the `Content-Length` header with the size of `data`.
|
||||
pub fn set_payload(&mut self, data: impl Into<Bytes>) -> &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
|
||||
}
|
||||
|
Reference in New Issue
Block a user