Skip to content

feat(builder): support header case methods #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/server/conn/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,55 @@ impl<E> Builder<E> {
}
}

/// Set whether HTTP/1 connections will write header names as title case at
/// the socket level.
///
/// This setting only affects HTTP/1 connections. HTTP/2 connections are
/// not affected by this setting.
///
/// Default is false.
///
/// # Example
///
/// ```
/// use hyper_util::{
/// rt::TokioExecutor,
/// server::conn::auto,
/// };
///
/// auto::Builder::new(TokioExecutor::new())
/// .title_case_headers(true);
/// ```
#[cfg(feature = "http1")]
pub fn title_case_headers(mut self, enabled: bool) -> Self {
self.http1.title_case_headers(enabled);
self
}

/// Set whether HTTP/1 connections will preserve the original case of header names.
///
/// This setting only affects HTTP/1 connections. HTTP/2 connections are
/// not affected by this setting.
///
/// Default is false.
///
/// # Example
///
/// ```
/// use hyper_util::{
/// rt::TokioExecutor,
/// server::conn::auto,
/// };
///
/// auto::Builder::new(TokioExecutor::new())
/// .preserve_header_case(true);
/// ```
#[cfg(feature = "http1")]
pub fn preserve_header_case(mut self, enabled: bool) -> Self {
self.http1.preserve_header_case(enabled);
self
}

/// Bind a connection together with a [`Service`].
pub fn serve_connection<I, S, B>(&self, io: I, service: S) -> Connection<'_, I, S, E>
where
Expand Down Expand Up @@ -1112,6 +1161,30 @@ mod tests {
// builder.serve_connection(io, service);
}

#[test]
#[cfg(feature = "http1")]
fn title_case_headers_configuration() {
// Test title_case_headers can be set on the main builder
auto::Builder::new(TokioExecutor::new()).title_case_headers(true);

// Can be combined with other configuration
auto::Builder::new(TokioExecutor::new())
.title_case_headers(true)
.http1_only();
}

#[test]
#[cfg(feature = "http1")]
fn preserve_header_case_configuration() {
// Test preserve_header_case can be set on the main builder
auto::Builder::new(TokioExecutor::new()).preserve_header_case(true);

// Can be combined with other configuration
auto::Builder::new(TokioExecutor::new())
.preserve_header_case(true)
.http1_only();
}

#[cfg(not(miri))]
#[tokio::test]
async fn http1() {
Expand Down