Skip to content

Commit a1400a8

Browse files
GlenDCfinnbearpaolobarbolinialpeb
committed
sync up with relevant changes of hyper-util
- feat(server): support 'auto_date_header', 'max_local_error_reset_streams', and 'ignore_invalid_headers'. (hyperium/hyper-util#161) - refactor: replace manual implementations of 'ReadBufCursor' methods (hyperium/hyper-util#181) - feat(rt): add 'tracing' feature that will propagate span context in TokioExecutor (hyperium/hyper-util#166) Co-authored-by: Finn Bear <finntbear@gmail.com> Co-authored-by: Paolo Barbolini <paolo@paolo565.org> Co-authored-by: Alejandro Pedraza <alejandro.pedraza@gmail.com>
1 parent ce2b60e commit a1400a8

File tree

5 files changed

+88
-15
lines changed

5 files changed

+88
-15
lines changed

FORK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ as a distant relative.
1111

1212
- <https://github.com/hyperium/h2/tree/adab70fd9f9e5ce3099d274a4b548a27bfdee4dc>
1313
- <https://github.com/hyperium/hyper/tree/v1.6.0>
14-
- <https://github.com/hyperium/hyper-util/tree/v0.1.10>
14+
- <https://github.com/hyperium/hyper-util/tree/e74ab7888638e768de17c47ed5f20c8b623a308f>
1515

1616
### tower-rs
1717

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ <h2>Supported by</h2>
664664
</main>
665665

666666
<footer>
667-
<p>© 2024 <a href="https://plabayo.tech">Plabayo</a>. Rama is dual-licensed under <a
667+
<p>© 2022&nbsp;&mdash;&nbsp;2025 <a href="https://plabayo.tech">Plabayo</a>. Rama is dual-licensed under <a
668668
href="https://github.com/plabayo/rama/blob/main/LICENSE-MIT">MIT</a> and <a
669669
href="https://github.com/plabayo/rama/blob/main/LICENSE-APACHE">Apache 2.0</a>.</p>
670670
<p>🦙 Made with love for and by the Rust community.</p>

rama-core/src/rt/executor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::graceful::ShutdownGuard;
2+
use tracing::instrument::Instrument;
23

34
/// Future executor that utilises `tokio` threads.
45
#[derive(Default, Debug, Clone)]
@@ -27,8 +28,8 @@ impl Executor {
2728
F: Future<Output: Send + 'static> + Send + 'static,
2829
{
2930
match &self.guard {
30-
Some(guard) => guard.spawn_task(future),
31-
None => tokio::spawn(future),
31+
Some(guard) => guard.spawn_task(future.in_current_span()),
32+
None => tokio::spawn(future.in_current_span()),
3233
}
3334
}
3435

rama-http-core/src/common/io/rewind.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ where
5555
// If there are no remaining bytes, let the bytes get dropped.
5656
if !prefix.is_empty() {
5757
let copy_len = cmp::min(prefix.len(), buf.remaining());
58-
// TODO: There should be a way to do following two lines cleaner...
5958
buf.put_slice(&prefix[..copy_len]);
6059
prefix.advance(copy_len);
6160
// Put back what's left

rama-http-core/src/server/conn/auto.rs

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

206224
pin_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

345368
pin_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

Comments
 (0)