Skip to content

Commit

Permalink
Support QUIC and HTTP/3.
Browse files Browse the repository at this point in the history
This commit adds support for HTTP/3 and QUIC under a disabled-by-default
feature `http3-preview`. The current implementation depends on modified
versions of h3 and s2n-quic-h3 which will need to be upstreamed and
published before a release is possible.

During the course of development various facets of Rocket's internal
connection handling and recent listener APIs were improved. The complete
list of changes included in this PR is:

  * A `shutdown` module was introduced.
  * `config::Shutdown` was renamed to `ShutdownConfig` and moved to
    `shutdown` while being re-exported from `config`.
  * `ListenerAddr` is now called `Endpoint`. Various methods which
    previously referred to "addresses" now refer to "endpoints".
  * `Rocket::endpoint()` was renamed to `Rocket::endpoints()` and now
    returns an iterator over the endpoints Rocket is listening on.
  * `Endpoint` acquired various query utility methods.
  * The `{set_}remote()` methods now take/produce `Endpoint`s.
  * `TlsBindable` only accepts single-phase internal interfaces.
  * Bind error messages include candidate endpoint info when possible.
  * The warning message when a secret key is not configured now includes
    information about its effect on private cookies.

Internal changes include:

  * Config module tests were moved to `config/tests.rs`.
  * The cancellable I/O implementation was significantly simplified.
  * The `TripWire` implementation was simplified.
  * Individual shutdown stages can now be awaited on via `Stages`.
  * The `Shield` implementation was simplified.

Resolves #2723.
  • Loading branch information
SergioBenitez committed Mar 19, 2024
1 parent 50c44e8 commit 1619bbb
Show file tree
Hide file tree
Showing 49 changed files with 1,529 additions and 1,037 deletions.
2 changes: 1 addition & 1 deletion benchmarks/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn client(routes: Vec<Route>) -> Client {
profile: Config::RELEASE_PROFILE,
log_level: rocket::config::LogLevel::Off,
cli_colors: config::CliColors::Never,
shutdown: config::Shutdown {
shutdown: config::ShutdownConfig {
ctrlc: false,
#[cfg(unix)]
signals: HashSet::new(),
Expand Down
1 change: 1 addition & 0 deletions contrib/sync_db_pools/lib/tests/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod sqlite_shutdown_test {

let options = map!["url" => ":memory:"];
let config = Figment::from(rocket::Config::debug_default())
.merge(("port", 0))
.merge(("databases", map!["test" => &options]));

rocket::custom(config).attach(Pool::fairing())
Expand Down
14 changes: 12 additions & 2 deletions core/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ all-features = true
[features]
default = ["http2", "tokio-macros"]
http2 = ["hyper/http2", "hyper-util/http2"]
http3-preview = ["s2n-quic", "s2n-quic-h3", "tls"]
secrets = ["cookie/private", "cookie/key-expansion"]
json = ["serde_json"]
msgpack = ["rmp-serde"]
Expand Down Expand Up @@ -76,8 +77,7 @@ futures = { version = "0.3.30", default-features = false, features = ["std"] }
state = "0.6"

[dependencies.hyper-util]
git = "https://github.com/SergioBenitez/hyper-util.git"
branch = "fix-readversion"
version = "0.1.3"
default-features = false
features = ["http1", "server", "tokio"]

Expand All @@ -99,6 +99,16 @@ version = "0.6.0-dev"
path = "../http"
features = ["serde"]

[dependencies.s2n-quic]
version = "1.32"
default-features = false
features = ["provider-address-token-default", "provider-tls-rustls"]
optional = true

[dependencies.s2n-quic-h3]
git = "https://github.com/SergioBenitez/s2n-quic-h3.git"
optional = true

[target.'cfg(unix)'.dependencies]
libc = "0.2.149"

Expand Down
15 changes: 8 additions & 7 deletions core/lib/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use yansi::{Paint, Style, Color::Primary};

use crate::log::PaintExt;
use crate::config::{LogLevel, Shutdown, Ident, CliColors};
use crate::config::{LogLevel, ShutdownConfig, Ident, CliColors};
use crate::request::{self, Request, FromRequest};
use crate::http::uncased::Uncased;
use crate::data::Limits;
Expand Down Expand Up @@ -120,8 +120,8 @@ pub struct Config {
#[cfg_attr(nightly, doc(cfg(feature = "secrets")))]
#[serde(serialize_with = "SecretKey::serialize_zero")]
pub secret_key: SecretKey,
/// Graceful shutdown configuration. **(default: [`Shutdown::default()`])**
pub shutdown: Shutdown,
/// Graceful shutdown configuration. **(default: [`ShutdownConfig::default()`])**
pub shutdown: ShutdownConfig,
/// Max level to log. **(default: _debug_ `normal` / _release_ `critical`)**
pub log_level: LogLevel,
/// Whether to use colors and emoji when logging. **(default:
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Config {
keep_alive: 5,
#[cfg(feature = "secrets")]
secret_key: SecretKey::zero(),
shutdown: Shutdown::default(),
shutdown: ShutdownConfig::default(),
log_level: LogLevel::Normal,
cli_colors: CliColors::Auto,
__non_exhaustive: (),
Expand Down Expand Up @@ -408,9 +408,10 @@ impl Config {
#[cfg(feature = "secrets")] {
launch_meta_!("secret key: {}", self.secret_key.paint(VAL));
if !self.secret_key.is_provided() {
warn!("secrets enabled without a stable `secret_key`");
launch_meta_!("disable `secrets` feature or configure a `secret_key`");
launch_meta_!("this becomes an {} in non-debug profiles", "error".red());
warn!("secrets enabled without configuring a stable `secret_key`");
warn_!("private/signed cookies will become unreadable after restarting");
launch_meta_!("disable the `secrets` feature or configure a `secret_key`");
launch_meta_!("this becomes a {} in non-debug profiles", "hard error".red());
}
}
}
Expand Down
Loading

0 comments on commit 1619bbb

Please sign in to comment.