This commit is contained in:
Yuki Okushi 2026-02-26 21:31:51 +09:00
parent 6c9a0a7ebb
commit 0131bd5420
5 changed files with 36 additions and 9 deletions

View File

@ -2,6 +2,10 @@
## Unreleased
- Encode the HTTP/1 `Connection: Upgrade` header in Camel-Case when camel-case header formatting is enabled.[#3953]
[#3953]: https://github.com/actix/actix-web/pull/3953
## 3.12.0
- Minimum supported Rust version (MSRV) is now 1.88.

View File

@ -117,7 +117,7 @@ pub(crate) trait MessageType: Sized {
} else {
dst.put_slice(b"connection: upgrade\r\n")
}
},
}
ConnectionType::KeepAlive if version < Version::HTTP_11 => {
if camel_case {
dst.put_slice(b"Connection: keep-alive\r\n")
@ -586,6 +586,16 @@ mod tests {
assert!(data.contains("Date: date\r\n"));
assert!(data.contains("Upgrade-Insecure-Requests: 1\r\n"));
let _ = head.encode_headers(
&mut bytes,
Version::HTTP_11,
BodySize::None,
ConnectionType::Upgrade,
&ServiceConfig::default(),
);
let data = String::from_utf8(Vec::from(bytes.split().freeze().as_ref())).unwrap();
assert!(data.contains("Connection: Upgrade\r\n"));
let _ = head.encode_headers(
&mut bytes,
Version::HTTP_11,

View File

@ -61,14 +61,15 @@ impl RequestHead {
&mut self.headers
}
/// Is to uppercase headers with Camel-Case.
/// Default is `false`
/// Returns whether headers should be sent in Camel-Case.
///
/// Default is `false`.
#[inline]
pub fn camel_case_headers(&self) -> bool {
self.flags.contains(Flags::CAMEL_CASE)
}
/// Set `true` to send headers which are formatted as Camel-Case.
/// Sets whether to send headers formatted as Camel-Case.
#[inline]
pub fn set_camel_case_headers(&mut self, val: bool) {
if val {

View File

@ -2,6 +2,10 @@
## Unreleased
- Add camel-case header controls to `WebsocketsRequest` via `camel_case_headers()` and `set_camel_case_headers()`. [#3953]
[#3953]: https://github.com/actix/actix-web/pull/3953
## 3.8.2
- Minimum supported Rust version (MSRV) is now 1.88.

View File

@ -245,17 +245,19 @@ impl WebsocketsRequest {
self.header(AUTHORIZATION, format!("Bearer {}", token))
}
/// Is to uppercase headers with Camel-Case.
/// Default is `false`
/// Returns whether headers should be sent in Camel-Case.
///
/// Default is `false`.
#[inline]
pub fn camel_case_headers(&self) -> bool {
self.head.camel_case_headers()
}
/// Set `true` to send headers which are formatted as Camel-Case.
/// Sets whether to send headers formatted as Camel-Case.
#[inline]
pub fn set_camel_case_headers(&mut self, val: bool) {
self.head.set_camel_case_headers(val)
pub fn set_camel_case_headers(mut self, val: bool) -> Self {
self.head.set_camel_case_headers(val);
self
}
/// Complete request construction and connect to a WebSocket server.
@ -542,6 +544,12 @@ mod tests {
let _ = req.connect();
}
#[actix_rt::test]
async fn camel_case_headers() {
let req = Client::new().ws("/").set_camel_case_headers(true);
assert!(req.camel_case_headers());
}
#[actix_rt::test]
async fn basics() {
let req = Client::new()