Skip to content

Commit 46826ea

Browse files
authored
feat(server): support auto_date_header, max_local_error_reset_streams, and ignore_invalid_headers. (#161)
1 parent 26e1e15 commit 46826ea

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ features = ["full"]
1818
rustdoc-args = ["--cfg", "docsrs"]
1919

2020
[dependencies]
21-
hyper = "1.4.0"
21+
hyper = "1.6.0"
2222
futures-util = { version = "0.3.16", default-features = false }
2323
http = "1.0"
2424
http-body = "1.0.0"

src/server/conn/auto/mod.rs

+45
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,16 @@ impl<E> Http1Builder<'_, E> {
653653
Http2Builder { inner: self.inner }
654654
}
655655

656+
/// Set whether the `date` header should be included in HTTP responses.
657+
///
658+
/// Note that including the `date` header is recommended by RFC 7231.
659+
///
660+
/// Default is true.
661+
pub fn auto_date_header(&mut self, enabled: bool) -> &mut Self {
662+
self.inner.http1.auto_date_header(enabled);
663+
self
664+
}
665+
656666
/// Set whether HTTP/1 connections should support half-closures.
657667
///
658668
/// Clients can chose to shutdown their write-side while waiting
@@ -685,6 +695,18 @@ impl<E> Http1Builder<'_, E> {
685695
self
686696
}
687697

698+
/// Set whether HTTP/1 connections will silently ignored malformed header lines.
699+
///
700+
/// If this is enabled and a header line does not start with a valid header
701+
/// name, or does not include a colon at all, the line will be silently ignored
702+
/// and no error will be reported.
703+
///
704+
/// Default is false.
705+
pub fn ignore_invalid_headers(&mut self, enabled: bool) -> &mut Self {
706+
self.inner.http1.ignore_invalid_headers(enabled);
707+
self
708+
}
709+
688710
/// Set whether to support preserving original header cases.
689711
///
690712
/// Currently, this will record the original cases received, and store them
@@ -861,6 +883,19 @@ impl<E> Http2Builder<'_, E> {
861883
self
862884
}
863885

886+
/// Configures the maximum number of local reset streams allowed before a GOAWAY will be sent.
887+
///
888+
/// If not set, hyper will use a default, currently of 1024.
889+
///
890+
/// If `None` is supplied, hyper will not apply any limit.
891+
/// This is not advised, as it can potentially expose servers to DOS vulnerabilities.
892+
///
893+
/// See <https://rustsec.org/advisories/RUSTSEC-2024-0003.html> for more information.
894+
pub fn max_local_error_reset_streams(&mut self, max: impl Into<Option<usize>>) -> &mut Self {
895+
self.inner.http2.max_local_error_reset_streams(max);
896+
self
897+
}
898+
864899
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
865900
/// stream-level flow control.
866901
///
@@ -980,6 +1015,16 @@ impl<E> Http2Builder<'_, E> {
9801015
self
9811016
}
9821017

1018+
/// Set whether the `date` header should be included in HTTP responses.
1019+
///
1020+
/// Note that including the `date` header is recommended by RFC 7231.
1021+
///
1022+
/// Default is true.
1023+
pub fn auto_date_header(&mut self, enabled: bool) -> &mut Self {
1024+
self.inner.http2.auto_date_header(enabled);
1025+
self
1026+
}
1027+
9831028
/// Bind a connection together with a [`Service`].
9841029
pub async fn serve_connection<I, S, B>(&self, io: I, service: S) -> Result<()>
9851030
where

0 commit comments

Comments
 (0)