Skip to content

Commit

Permalink
feat(server): implement forgotten settings for case preserving
Browse files Browse the repository at this point in the history
  • Loading branch information
nox authored and seanmonstar committed Apr 22, 2021
1 parent a303b3c commit 4fd6c4c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
11 changes: 9 additions & 2 deletions examples/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ type HttpClient = Client<hyper::client::HttpConnector>;
#[tokio::main]
async fn main() {
let addr = SocketAddr::from(([127, 0, 0, 1], 8100));
let client = HttpClient::new();

let client = Client::builder()
.http1_title_case_headers(true)
.http1_preserve_header_case(true)
.build_http();

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

let server = Server::bind(&addr).serve(make_service);
let server = Server::bind(&addr)
.http1_preserve_header_case(true)
.http1_title_case_headers(true)
.serve(make_service);

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

Expand Down
19 changes: 19 additions & 0 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct Http<E = Exec> {
h1_half_close: bool,
h1_keep_alive: bool,
h1_title_case_headers: bool,
h1_preserve_header_case: bool,
#[cfg(feature = "http2")]
h2_builder: proto::h2::server::Config,
mode: ConnectionMode,
Expand Down Expand Up @@ -236,6 +237,7 @@ impl Http {
h1_half_close: false,
h1_keep_alive: true,
h1_title_case_headers: false,
h1_preserve_header_case: false,
#[cfg(feature = "http2")]
h2_builder: Default::default(),
mode: ConnectionMode::default(),
Expand Down Expand Up @@ -301,6 +303,19 @@ impl<E> Http<E> {
self
}

/// Set whether HTTP/1 connections will write header names as provided
/// at the socket level.
///
/// Note that this setting does not affect HTTP/2.
///
/// Default is false.
#[cfg(feature = "http1")]
#[cfg_attr(docsrs, doc(cfg(feature = "http1")))]
pub fn http1_preserve_header_case(&mut self, enabled: bool) -> &mut Self {
self.h1_preserve_header_case = enabled;
self
}

/// Sets whether HTTP2 is required.
///
/// Default is false
Expand Down Expand Up @@ -475,6 +490,7 @@ impl<E> Http<E> {
h1_half_close: self.h1_half_close,
h1_keep_alive: self.h1_keep_alive,
h1_title_case_headers: self.h1_title_case_headers,
h1_preserve_header_case: self.h1_preserve_header_case,
#[cfg(feature = "http2")]
h2_builder: self.h2_builder,
mode: self.mode,
Expand Down Expand Up @@ -533,6 +549,9 @@ impl<E> Http<E> {
if self.h1_title_case_headers {
conn.set_title_case_headers();
}
if self.h1_preserve_header_case {
conn.set_preserve_header_case();
}
conn.set_flush_pipeline(self.pipeline_flush);
if let Some(max) = self.max_buf_size {
conn.set_max_buf_size(max);
Expand Down
13 changes: 13 additions & 0 deletions src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ impl<I, E> Builder<I, E> {
self
}

/// Set whether HTTP/1 connections will write header names as provided
/// at the socket level.
///
/// Note that this setting does not affect HTTP/2.
///
/// Default is false.
#[cfg(feature = "http1")]
#[cfg_attr(docsrs, doc(cfg(feature = "http1")))]
pub fn http1_preserve_header_case(mut self, val: bool) -> Self {
self.protocol.http1_preserve_header_case(val);
self
}

/// Sets whether HTTP/1 is required.
///
/// Default is `false`.
Expand Down

0 comments on commit 4fd6c4c

Please sign in to comment.