Skip to content

Commit 4fd6c4c

Browse files
noxseanmonstar
authored andcommitted
feat(server): implement forgotten settings for case preserving
1 parent a303b3c commit 4fd6c4c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

examples/http_proxy.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ type HttpClient = Client<hyper::client::HttpConnector>;
2323
#[tokio::main]
2424
async fn main() {
2525
let addr = SocketAddr::from(([127, 0, 0, 1], 8100));
26-
let client = HttpClient::new();
26+
27+
let client = Client::builder()
28+
.http1_title_case_headers(true)
29+
.http1_preserve_header_case(true)
30+
.build_http();
2731

2832
let make_service = make_service_fn(move |_| {
2933
let client = client.clone();
3034
async move { Ok::<_, Infallible>(service_fn(move |req| proxy(client.clone(), req))) }
3135
});
3236

33-
let server = Server::bind(&addr).serve(make_service);
37+
let server = Server::bind(&addr)
38+
.http1_preserve_header_case(true)
39+
.http1_title_case_headers(true)
40+
.serve(make_service);
3441

3542
println!("Listening on http://{}", addr);
3643

src/server/conn.rs

+19
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub struct Http<E = Exec> {
8989
h1_half_close: bool,
9090
h1_keep_alive: bool,
9191
h1_title_case_headers: bool,
92+
h1_preserve_header_case: bool,
9293
#[cfg(feature = "http2")]
9394
h2_builder: proto::h2::server::Config,
9495
mode: ConnectionMode,
@@ -236,6 +237,7 @@ impl Http {
236237
h1_half_close: false,
237238
h1_keep_alive: true,
238239
h1_title_case_headers: false,
240+
h1_preserve_header_case: false,
239241
#[cfg(feature = "http2")]
240242
h2_builder: Default::default(),
241243
mode: ConnectionMode::default(),
@@ -301,6 +303,19 @@ impl<E> Http<E> {
301303
self
302304
}
303305

306+
/// Set whether HTTP/1 connections will write header names as provided
307+
/// at the socket level.
308+
///
309+
/// Note that this setting does not affect HTTP/2.
310+
///
311+
/// Default is false.
312+
#[cfg(feature = "http1")]
313+
#[cfg_attr(docsrs, doc(cfg(feature = "http1")))]
314+
pub fn http1_preserve_header_case(&mut self, enabled: bool) -> &mut Self {
315+
self.h1_preserve_header_case = enabled;
316+
self
317+
}
318+
304319
/// Sets whether HTTP2 is required.
305320
///
306321
/// Default is false
@@ -475,6 +490,7 @@ impl<E> Http<E> {
475490
h1_half_close: self.h1_half_close,
476491
h1_keep_alive: self.h1_keep_alive,
477492
h1_title_case_headers: self.h1_title_case_headers,
493+
h1_preserve_header_case: self.h1_preserve_header_case,
478494
#[cfg(feature = "http2")]
479495
h2_builder: self.h2_builder,
480496
mode: self.mode,
@@ -533,6 +549,9 @@ impl<E> Http<E> {
533549
if self.h1_title_case_headers {
534550
conn.set_title_case_headers();
535551
}
552+
if self.h1_preserve_header_case {
553+
conn.set_preserve_header_case();
554+
}
536555
conn.set_flush_pipeline(self.pipeline_flush);
537556
if let Some(max) = self.max_buf_size {
538557
conn.set_max_buf_size(max);

src/server/server.rs

+13
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ impl<I, E> Builder<I, E> {
244244
self
245245
}
246246

247+
/// Set whether HTTP/1 connections will write header names as provided
248+
/// at the socket level.
249+
///
250+
/// Note that this setting does not affect HTTP/2.
251+
///
252+
/// Default is false.
253+
#[cfg(feature = "http1")]
254+
#[cfg_attr(docsrs, doc(cfg(feature = "http1")))]
255+
pub fn http1_preserve_header_case(mut self, val: bool) -> Self {
256+
self.protocol.http1_preserve_header_case(val);
257+
self
258+
}
259+
247260
/// Sets whether HTTP/1 is required.
248261
///
249262
/// Default is `false`.

0 commit comments

Comments
 (0)