@@ -56,6 +56,8 @@ impl Builder {
5656 /// Only accepts HTTP/2
5757 ///
5858 /// Does not do anything if used with [`serve_connection_with_upgrades`]
59+ ///
60+ /// [`serve_connection_with_upgrades`]: Builder::serve_connection_with_upgrades
5961 pub fn http2_only ( mut self ) -> Self {
6062 assert ! ( self . version. is_none( ) ) ;
6163 self . version = Some ( Version :: H2 ) ;
@@ -65,12 +67,32 @@ impl Builder {
6567 /// Only accepts HTTP/1
6668 ///
6769 /// Does not do anything if used with [`serve_connection_with_upgrades`]
70+ ///
71+ /// [`serve_connection_with_upgrades`]: Builder::serve_connection_with_upgrades
6872 pub fn http1_only ( mut self ) -> Self {
6973 assert ! ( self . version. is_none( ) ) ;
7074 self . version = Some ( Version :: H1 ) ;
7175 self
7276 }
7377
78+ /// Returns `true` if this builder can serve an HTTP/1.1-based connection.
79+ pub fn is_http1_available ( & self ) -> bool {
80+ match self . version {
81+ Some ( Version :: H1 ) => true ,
82+ Some ( Version :: H2 ) => false ,
83+ _ => true ,
84+ }
85+ }
86+
87+ /// Returns `true` if this builder can serve an HTTP/2-based connection.
88+ pub fn is_http2_available ( & self ) -> bool {
89+ match self . version {
90+ Some ( Version :: H1 ) => false ,
91+ Some ( Version :: H2 ) => true ,
92+ _ => true ,
93+ }
94+ }
95+
7496 /// Bind a connection together with a [`Service`].
7597 pub fn serve_connection < I , S > ( & self , io : I , service : S ) -> Connection < ' _ , I , S >
7698 where
@@ -101,10 +123,6 @@ impl Builder {
101123 /// Bind a connection together with a [`Service`], with the ability to
102124 /// handle HTTP upgrades. This requires that the IO object implements
103125 /// `Send`.
104- ///
105- /// Note that if you ever want to use [`hyper::upgrade::Upgraded::downcast`]
106- /// with this crate, you'll need to use [`hyper_util::server::conn::auto::upgrade::downcast`]
107- /// instead. See the documentation of the latter to understand why.
108126 pub fn serve_connection_with_upgrades < I , S > (
109127 & self ,
110128 io : I ,
@@ -204,7 +222,12 @@ where
204222}
205223
206224pin_project ! {
207- /// Connection future.
225+ /// A [`Future`](core::future::Future) representing an HTTP/1 connection, returned from
226+ /// [`Builder::serve_connection`](struct.Builder.html#method.serve_connection).
227+ ///
228+ /// To drive HTTP on this connection this future **must be polled**, typically with
229+ /// `.await`. If it isn't polled, no progress will be made on this connection.
230+ #[ must_use = "futures do nothing unless polled" ]
208231 pub struct Connection <' a, I , S >
209232 where
210233 S : HttpService <Incoming >,
@@ -343,7 +366,12 @@ where
343366}
344367
345368pin_project ! {
346- /// Connection future.
369+ /// An upgradable [`Connection`], returned by
370+ /// [`Builder::serve_upgradable_connection`](struct.Builder.html#method.serve_connection_with_upgrades).
371+ ///
372+ /// To drive HTTP on this connection this future **must be polled**, typically with
373+ /// `.await`. If it isn't polled, no progress will be made on this connection.
374+ #[ must_use = "futures do nothing unless polled" ]
347375 pub struct UpgradeableConnection <' a, I , S >
348376 where
349377 S : HttpService <Incoming >,
@@ -474,6 +502,16 @@ impl Http1Builder<'_> {
474502 Http2Builder { inner : self . inner }
475503 }
476504
505+ /// Set whether the `date` header should be included in HTTP responses.
506+ ///
507+ /// Note that including the `date` header is recommended by RFC 7231.
508+ ///
509+ /// Default is true.
510+ pub fn auto_date_header ( & mut self , enabled : bool ) -> & mut Self {
511+ self . inner . http1 . auto_date_header ( enabled) ;
512+ self
513+ }
514+
477515 /// Set whether HTTP/1 connections should support half-closures.
478516 ///
479517 /// Clients can chose to shutdown their write-side while waiting
@@ -506,6 +544,18 @@ impl Http1Builder<'_> {
506544 self
507545 }
508546
547+ /// Set whether HTTP/1 connections will silently ignored malformed header lines.
548+ ///
549+ /// If this is enabled and a header line does not start with a valid header
550+ /// name, or does not include a colon at all, the line will be silently ignored
551+ /// and no error will be reported.
552+ ///
553+ /// Default is false.
554+ pub fn ignore_invalid_headers ( & mut self , enabled : bool ) -> & mut Self {
555+ self . inner . http1 . ignore_invalid_headers ( enabled) ;
556+ self
557+ }
558+
509559 /// Set the maximum number of headers.
510560 ///
511561 /// When a request is received, the parser will reserve a buffer to store headers for optimal
@@ -545,7 +595,7 @@ impl Http1Builder<'_> {
545595 /// Setting this to true will force hyper to use queued strategy
546596 /// which may eliminate unnecessary cloning on some TLS backends
547597 ///
548- /// Default is `auto`. In this mode hyper will try to guess which
598+ /// Default is `auto`. In this mode rama-http-core will try to guess which
549599 /// mode to use
550600 pub fn writev ( & mut self , val : bool ) -> & mut Self {
551601 self . inner . http1 . writev ( val) ;
@@ -621,12 +671,25 @@ impl Http2Builder<'_> {
621671 self
622672 }
623673
674+ /// Configures the maximum number of local reset streams allowed before a GOAWAY will be sent.
675+ ///
676+ /// If not set, rama-http-core will use a default, currently of 1024.
677+ ///
678+ /// If `None` is supplied, rama-http-core will not apply any limit.
679+ /// This is not advised, as it can potentially expose servers to DOS vulnerabilities.
680+ ///
681+ /// See <https://rustsec.org/advisories/RUSTSEC-2024-0003.html> for more information.
682+ pub fn max_local_error_reset_streams ( & mut self , max : impl Into < Option < usize > > ) -> & mut Self {
683+ self . inner . http2 . max_local_error_reset_streams ( max) ;
684+ self
685+ }
686+
624687 /// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
625688 /// stream-level flow control.
626689 ///
627690 /// Passing `None` will do nothing.
628691 ///
629- /// If not set, hyper will use a default.
692+ /// If not set, rama-http-core will use a default.
630693 ///
631694 /// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
632695 pub fn initial_stream_window_size ( & mut self , sz : impl Into < Option < u32 > > ) -> & mut Self {
@@ -638,7 +701,7 @@ impl Http2Builder<'_> {
638701 ///
639702 /// Passing `None` will do nothing.
640703 ///
641- /// If not set, hyper will use a default.
704+ /// If not set, rama-http-core will use a default.
642705 pub fn initial_connection_window_size ( & mut self , sz : impl Into < Option < u32 > > ) -> & mut Self {
643706 self . inner . http2 . initial_connection_window_size ( sz) ;
644707 self
@@ -658,7 +721,7 @@ impl Http2Builder<'_> {
658721 ///
659722 /// Passing `None` will do nothing.
660723 ///
661- /// If not set, hyper will use a default.
724+ /// If not set, rama-http-core will use a default.
662725 pub fn max_frame_size ( & mut self , sz : impl Into < Option < u32 > > ) -> & mut Self {
663726 self . inner . http2 . max_frame_size ( sz) ;
664727 self
@@ -731,6 +794,16 @@ impl Http2Builder<'_> {
731794 self
732795 }
733796
797+ /// Set whether the `date` header should be included in HTTP responses.
798+ ///
799+ /// Note that including the `date` header is recommended by RFC 7231.
800+ ///
801+ /// Default is true.
802+ pub fn auto_date_header ( & mut self , enabled : bool ) -> & mut Self {
803+ self . inner . http2 . auto_date_header ( enabled) ;
804+ self
805+ }
806+
734807 /// Bind a connection together with a [`Service`].
735808 pub async fn serve_connection < I , S > ( & self , io : I , service : S ) -> Result < ( ) >
736809 where
0 commit comments