Skip to content

Commit 0ea2613

Browse files
feat(server): support header case methods on auto::Builder (#207)
* feat(builder): add title_case_headers * feat(builder): add preserve_header_case
1 parent d891931 commit 0ea2613

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

src/server/conn/auto/mod.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,55 @@ impl<E> Builder<E> {
161161
}
162162
}
163163

164+
/// Set whether HTTP/1 connections will write header names as title case at
165+
/// the socket level.
166+
///
167+
/// This setting only affects HTTP/1 connections. HTTP/2 connections are
168+
/// not affected by this setting.
169+
///
170+
/// Default is false.
171+
///
172+
/// # Example
173+
///
174+
/// ```
175+
/// use hyper_util::{
176+
/// rt::TokioExecutor,
177+
/// server::conn::auto,
178+
/// };
179+
///
180+
/// auto::Builder::new(TokioExecutor::new())
181+
/// .title_case_headers(true);
182+
/// ```
183+
#[cfg(feature = "http1")]
184+
pub fn title_case_headers(mut self, enabled: bool) -> Self {
185+
self.http1.title_case_headers(enabled);
186+
self
187+
}
188+
189+
/// Set whether HTTP/1 connections will preserve the original case of header names.
190+
///
191+
/// This setting only affects HTTP/1 connections. HTTP/2 connections are
192+
/// not affected by this setting.
193+
///
194+
/// Default is false.
195+
///
196+
/// # Example
197+
///
198+
/// ```
199+
/// use hyper_util::{
200+
/// rt::TokioExecutor,
201+
/// server::conn::auto,
202+
/// };
203+
///
204+
/// auto::Builder::new(TokioExecutor::new())
205+
/// .preserve_header_case(true);
206+
/// ```
207+
#[cfg(feature = "http1")]
208+
pub fn preserve_header_case(mut self, enabled: bool) -> Self {
209+
self.http1.preserve_header_case(enabled);
210+
self
211+
}
212+
164213
/// Bind a connection together with a [`Service`].
165214
pub fn serve_connection<I, S, B>(&self, io: I, service: S) -> Connection<'_, I, S, E>
166215
where
@@ -1112,6 +1161,30 @@ mod tests {
11121161
// builder.serve_connection(io, service);
11131162
}
11141163

1164+
#[test]
1165+
#[cfg(feature = "http1")]
1166+
fn title_case_headers_configuration() {
1167+
// Test title_case_headers can be set on the main builder
1168+
auto::Builder::new(TokioExecutor::new()).title_case_headers(true);
1169+
1170+
// Can be combined with other configuration
1171+
auto::Builder::new(TokioExecutor::new())
1172+
.title_case_headers(true)
1173+
.http1_only();
1174+
}
1175+
1176+
#[test]
1177+
#[cfg(feature = "http1")]
1178+
fn preserve_header_case_configuration() {
1179+
// Test preserve_header_case can be set on the main builder
1180+
auto::Builder::new(TokioExecutor::new()).preserve_header_case(true);
1181+
1182+
// Can be combined with other configuration
1183+
auto::Builder::new(TokioExecutor::new())
1184+
.preserve_header_case(true)
1185+
.http1_only();
1186+
}
1187+
11151188
#[cfg(not(miri))]
11161189
#[tokio::test]
11171190
async fn http1() {

0 commit comments

Comments
 (0)