Commit Graph

932 Commits

Author SHA1 Message Date
Sergio Benitez dcde224648 Update dependencies and fix nightly warnings. 2024-04-11 18:09:21 -07:00
Wesley Rosenblum 07e4170b72 Use 's2n-quic' TLS server builder. 2024-04-10 14:06:58 -07:00
Łukasz Wojniłowicz a742d3da4f Symlink license files in all crate directories.
Resolves #2760.
2024-04-06 20:46:07 -07:00
Sergio Benitez edce8bd656 Use default 'CryptoProvider' for all TLS ops.
Prior to this commit, some TLS related operations used 'ring' even when
a different default 'CryptoProvider' was installed. This commit fixes
that by refactoring 'TlsConfig' such that all utility methods are
required to use the default 'CryptoProvider'.

This commit also cleans up code related to the rustls 0.23 update.
2024-03-31 11:46:56 -07:00
Abdullah Alyan ce92c5dd76 Update rustls to 0.23. Support 'CryptoProvider's.
This commit updates rustls to 0.23 and adds support for custom
'CryptoProvider's installable via 'CryptoProvider::install_default()'.
In particular, this enables using `aws-lc-rs` for cryptography related
operation in TLS. The 'TLS' example was updated to test use of
'aws-lc-rs' on Unix.
2024-03-31 11:46:56 -07:00
Sergio Benitez bd26ca462a Introduce #[suppress]: suppress Rocket lints.
Adding `#[suppress(lint)]` for a known `lint` suppresses the
corresponding warning generated by Rocket's codegen. The lints are:

  * `unknown_format`
  * `dubious_payload`
  * `segment_chars`
  * `arbitrary_main`
  * `sync_spawn`

For example, the following works as expected to suppress the warning
generated by the unknown media type "application/foo":

```rust
fn post_foo() -> &'static str { "post_foo" }
```

Resolves #1188.
2024-03-21 20:24:53 -07:00
Tau 35a1cf12b6 Fix and always set Content-Length header.
Previously, the header was erroneously set as 'Content-Type' and not
visible to local clients. This commit fixes both of these issues.
2024-03-21 16:42:09 -07:00
Sergio Benitez 8f3061ba40 Rename 'candidate_endpoint()', 'bind_endpoint()'. 2024-03-20 14:29:32 -07:00
Sergio Benitez 225655817a Update 'x509-parser' to 0.16. 2024-03-20 01:37:31 -07:00
Sergio Benitez 02011a1307 Clean up codebase: fix reasonable clippy warnings.
This commit is a codebase-wide cleanup driven by clippy warnings. In
addition to fixing every reasonable warning, the following new
functionality was introduced:

  * `Accept::new()` now takes any `T: Into<QMediaType>` iterator.
  * `TempFile::is_empty()` was added.
  * `HeaderMap` now implements `IntoIterator`.

This commit makes the following breaking changes:

  * The `IntoCollection` trait is gone. Generics previously bound by the
    trait are now bound by `IntoIterator`. This affects:
    - `Accept::new()`
    - `ContentType::with_params()`
    - `Permission::{allow, allowed}()`
  * `MediaType`, `QMediaType`, and `Allow` implement `IntoIterator`,
    enabling most existing code to continue working without change.
  * The inherent `HeaderMap::into_iter()` method was removed.
  * The `Ok` variant in ErrorKind::Liftoff` is now `Box<Rocket<Orbit>>`.
2024-03-20 00:47:38 -07:00
Sergio Benitez d9249db6d6 Address new nightly compiler warnings. 2024-03-19 14:08:14 -07:00
Sergio Benitez 1619bbbddc Support QUIC and HTTP/3.
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.
2024-03-18 20:23:22 -07:00
Sergio Benitez 50c44e8fdc Allow displaying [T; N], Vec<T>, [u8] via 'uri!'.
Resolves #2750.
2024-03-14 15:26:03 -07:00
Sergio Benitez 7c702a5b01 Update yansi to 1.0.1. 2024-03-14 15:26:03 -07:00
Sergio Benitez 3927c931b2 Fix various typos in rustdocs. 2024-03-14 15:25:53 -07:00
Sergio Benitez d7bcef6cf3 Fix incorrect 'Accept' swap in rustdocs.
Resolves #2743.
2024-03-04 21:42:01 -08:00
John Bampton fd739bab4e Fix WebSocket FAQ entry, typos. 2024-03-04 12:37:29 -08:00
Sergio Benitez 53c5166b6c Fix '#[async_bound]' for fns with no return type. 2024-01-30 20:36:40 -08:00
Sergio Benitez 38dbab8dd3 Bump MSRV to 1.75 for `async fn` in traits. 2024-01-30 09:18:43 -08:00
Sergio Benitez fd294049c7 Update to hyper 1. Enable custom + unix listeners.
This commit completely rewrites Rocket's HTTP serving. In addition to
significant internal cleanup, this commit introduces the following major
features:

  * Support for custom, external listeners in the `listener` module.

    The new `listener` module contains new `Bindable`, `Listener`, and
    `Connection` traits which enable composable, external
    implementations of connection listeners. Rocket can launch on any
    `Listener`, or anything that can be used to create a listener
    (`Bindable`), via a new `launch_on()` method.

  * Support for Unix domain socket listeners out of the box.

    The default listener backwards compatibly supports listening on Unix
    domain sockets. To do so, configure an `address` of
    `unix:path/to/socket` and optional set `reuse` to `true` (the
    default) or `false` which controls whether Rocket will handle
    creating and deleting the unix domain socket.

In addition to these new features, this commit makes the following major
improvements:

  * Rocket now depends on hyper 1.

  * Rocket no longer depends on hyper to handle connections. This allows
    us to handle more connection failure conditions which results in an
    overall more robust server with fewer dependencies.

  * Logic to work around hyper's inability to reference incoming request
    data in the response results in a 15% performance improvement.

  * `Client`s can be marked secure with `Client::{un}tracked_secure()`,
    allowing Rocket to treat local connections as running under TLS.

  * The `macros` feature of `tokio` is no longer used by Rocket itself.
    Dependencies can take advantage of this reduction in compile-time
    cost by disabling the new default feature `tokio-macros`.

  * A new `TlsConfig::validate()` method allows checking a TLS config.

  * New `TlsConfig::{certs,key}_reader()`,
    `MtlsConfig::ca_certs_reader()` methods return `BufReader`s, which
    allow reading the configured certs and key directly.

  * A new `NamedFile::open_with()` constructor allows specifying
    `OpenOptions`.

These improvements resulted in the following breaking changes:

  * The MSRV is now 1.74.
  * `hyper` is no longer exported from `rocket::http`.
  * `IoHandler::io` takes `Box<Self>` instead of `Pin<Box<Self>>`.
    - Use `Box::into_pin(self)` to recover the previous type.
  * `Response::upgrade()` now returns an `&mut dyn IoHandler`, not
    `Pin<& mut _>`.
  * `Config::{address,port,tls,mtls}` methods have been removed.
    - Use methods on `Rocket::endpoint()` instead.
  * `TlsConfig` was moved to `tls::TlsConfig`.
  * `MutualTls` was renamed and moved to `mtls::MtlsConfig`.
  * `ErrorKind::TlsBind` was removed.
  * The second field of `ErrorKind::Shutdown` was removed.
  * `{Local}Request::{set_}remote()` methods take/return an `Endpoint`.
  * `Client::new()` was removed; it was previously deprecated.

Internally, the following major changes were made:

  * A new `async_bound` attribute macro was introduced to allow setting
    bounds on futures returned by `async fn`s in traits while
    maintaining good docs.

  * All utility functionality was moved to a new `util` module.

Resolves #2671.
Resolves #1070.
2024-01-29 22:38:55 -08:00
Sergio Benitez e9b568d9b2 Fixup docs for 'proxy_proto_header'. 2024-01-22 18:41:20 -08:00
Arjen 5c85ea3db5 Support configurable 'X-Forwarded-Proto'.
Co-authored-by: Sergio Benitez <sb@sergio.bz>
2024-01-22 18:41:20 -08:00
Sergio Benitez 915c1181da Forward whole-form errors in 'FromForm' derive.
Resolves #2672.
2024-01-17 12:15:01 -08:00
Sergio Benitez b3abc760ae Introduce chainable data transformers.
Resolves #775.
2023-12-27 20:02:14 -08:00
Sergio Benitez a285625f80 Upgrade 'smallvec' to simplify 'Accept' impl. 2023-12-23 23:34:23 -08:00
Sergio Benitez 3e33cfe37c Remove custom 'docify!' macro: use '#[doc]`. 2023-12-22 23:42:55 -08:00
Paul Lietar 67ad8316dc Ensure 'TempFile' flushes when persisted.
Tokio's `File::write_all()` method has an unexpected quirk: it doesn't
actually write all the requested content to the file when the returned
future resolves. Instead, the write is attempted and queued. This means
that the `persist()` method can resolve without the data being persisted
to the file system. Subsequent reads of the ostensibly written-to file
can thus fail to contain the expected data.

An call to `flush()` following `write_all()` would circumvent the issue.
Alternatively, calling `fs::write()` actually writes to the file system
before returning and requires fewer lines of code. This commit thus
swaps the call to `write_all()` with `fs::write()`.
2023-12-19 16:01:00 -08:00
Martyn ae7e0040e8 Document "reconnect ad-infinitum" SSE pitfall. 2023-12-19 14:41:28 -08:00
Sergio Benitez 7cf8b1368f Doc, fix, and test 'cli_colors' deserialization. 2023-12-18 16:37:56 -08:00
Lev Kokotov f4e8987a46 Make 'cli_colors' an enum, add "always" option.
Resolves #2649.
2023-12-18 16:34:13 -08:00
cui fliter 485c490b1f Fix typos: 'preceeding', 'occured'. 2023-12-18 15:39:09 -08:00
Sergio Benitez 9c2b74b23c Upgrade 'rustls' to '0.22'.
In the process, the following improvements were also made:

  * Error messages related to TLS were improved.
  * 'Redirector' in 'tls' example was improved.
2023-12-15 16:50:08 -08:00
Sergio Benitez a59f3c4c1f Fix min dependency versions. Update MSRV to 1.64.
Also includes a work-around for a buggy `format_args!` macro found in
rustc 1.67 and 1.68.

Resolves #2670.
2023-12-13 17:49:05 -08:00
Sergio Benitez 8d9dfcecad Silence more warnings in generated code.
Resolves #2655.
2023-12-05 17:55:56 -08:00
Sergio Benitez e526fa04d4 Update 'SergioBenitez/Rocket' to 'rwf2/Rocket'.
Resolves rwf2/rwf2#5.
2023-11-21 16:32:25 +01:00
Sergio Benitez 44ac3f1eb6 Move to 0.6.0-dev on master. 2023-11-18 11:30:50 +01:00
Sergio Benitez 6d467564d6 Update version numbers for 0.5.0. 2023-11-17 17:04:59 +01:00
Sergio Benitez 124ec94b46 Fix typos.
Co-authored-by: cui fliter <imcusg@gmail.com>
2023-11-17 17:04:49 +01:00
Sergio Benitez a1c29c735c New version: 0.5.0-rc.4.
New contrib versions: 0.1.0-rc.4.
2023-11-17 17:04:44 +01:00
Sergio Benitez 15637186ba Document '&[u8]' form/data guard, limits. 2023-11-01 18:51:26 -05:00
Sergio Benitez fa0c778276 Set 'SameSite' to 'Lax' on removal cookies.
This avoids needless warnings from certain browsers.
2023-11-01 12:08:26 -05:00
Sergio Benitez 48d1b82e84 Qualm various emerging unused warnings. 2023-11-01 01:16:28 -05:00
Sergio Benitez fbd1a0d069 Improve forwarding status code precision.
Previously, the `NotFound` status code was used to signal many kinds of
recoverable, forwarding errors. This included validation errors, incorrect
Content-Type errors, and more.

This commit modifies the status code used to forward in these instances to more
precisely indicate the forwarding condition. In particular:

  * Parameter `FromParam` errors now forward as 422 (`UnprocessableEntity`).
  * Query paramater errors now forward as 422 (`UnprocessableEntity`).
  * Use of incorrect form content-type forwards as 413 (`UnsupportedMediaType`).
  * `WebSocket` guard now forwards as 400 (`BadRequest`).
  * `&Host`, `&Accept`, `&ContentType`, `IpAddr`, and `SocketAddr` all forward
    with a 500 (`InternalServerError`).

Additionally, the `IntoOutcome` trait was overhauled to support functionality
previously offered by methods on `Outcome`. The `Outcome::forward()` method now
requires a status code to use for the forwarding outcome.

Finally, logging of `Outcome`s now includes the relevant status code.

Resolves #2626.
2023-10-31 18:44:37 -05:00
Sergio Benitez c90812051e Rename 'Outcome::Failure' to 'Outcome::Error'.
The primary motivation is to deconflate the leading `F`s in `Failure` and
`Forward`. In particular, when using a generics, we used `F` for forward, which
could easily be confused for `F` for `Failure`. This resolves the conflation.
2023-10-31 12:17:28 -05:00
Sergio Benitez 260e671d43 Use mixed-site spans to avoid clippy 'uri!' error.
Closes #2630.
2023-10-27 14:50:48 -05:00
许杰友 Jieyou Xu (Joe) 07fe79796f Use Span::mixed_site to avoid let unit warnings.
Closes #2568.
2023-10-16 17:50:49 -07:00
Ruben Schmidmeister 58adc48965 Set 'color-scheme' in default catcher HTML. 2023-10-16 15:29:51 -07:00
Sergio Benitez ae68742048 Update dependencies.
* notify: 5 -> 6
  * indexmap: 1 -> 2
  * cookie: 0.18.0-rc.0 -> 0.18
2023-10-09 17:03:21 -07:00
Sergio Benitez 47faac6080 Document that '&[u8]' is a form guard. 2023-10-02 11:59:03 -07:00
Sergio Benitez 5d31ad4efb Update 'cookie' to 0.18. 2023-09-28 23:50:29 -07:00
Sergio Benitez f41474dd61 Fix broken links between codegen and http crates.
Also resolves link warnings emitted by rustdoc.

Closes #2594
2023-09-20 17:17:22 -07:00
Sergio Benitez bbb124eeea Update UI tests for latest rustc. 2023-09-20 16:17:16 -07:00
Sergio Benitez 28de15858e Avoid using 'macro' items on stable.
This gets rid of the warning message on stable when building examples.
2023-09-20 16:17:16 -07:00
Sergio Benitez 2cf38a5aa3 Remove use of 'private_in_public' lint.
The lint no longer exists. This gets rid of a compile-time warning for users.

Resolves #2608.
2023-09-20 16:16:05 -07:00
Sergio Benitez 695cf3aab1 Update UI tests for latest `rustc`. 2023-08-25 15:23:29 -07:00
Manuel Transfeld aa7805a5f8 Update 'sqlx' to '0.7'. 2023-08-25 14:02:44 -07:00
Sergio Benitez ddeac5ddcf Remove unnecessary braces. 2023-08-14 14:16:56 -04:00
Sergio Benitez 5606b8e693 Clarify when 'UriDisplay' can be derived.
Resolves #2595.
2023-08-14 14:11:08 -04:00
Sergio Benitez b4c8597194 Update UI test expected results. 2023-08-11 15:14:37 -04:00
Sergio Benitez c337f75f32 Fix 'get_pending()' docs, functionality.
The `get_pending()` method now properly decrypts private cookies that were
present in the jar originally.

Resolves #2591.
2023-08-10 16:22:28 -04:00
Sergio Benitez c2936fcb1e Update 'yansi' to 1.0.0-rc. 2023-07-11 13:18:35 -07:00
Sergio Benitez 9a9cd76c01 Add support for 'diesel-async' to 'db_pools'. 2023-06-09 16:47:06 -07:00
Sergio Benitez a9549cd4e8 Remove use of 'unsafe' in 'RawStr' doctests. 2023-06-07 20:44:19 -07:00
Sergio Benitez 23bf83d50d Add 'mtls::Certificate::as_bytes()' method. 2023-06-07 17:59:59 -07:00
Sergio Benitez be92fe648b Update UI tests for latest rustc. 2023-05-25 11:59:46 -07:00
Sergio Benitez e3f1b53efa Update 'state' to 0.6. 2023-05-25 11:54:27 -07:00
Sergio Benitez afb5374157 Warn if a task is spawned in a sync '#[launch]'.
The warning is fairly conservative. Heuristics are used to determine if a call
to `tokio::spawn()` occurs in the `#[launch]` function.

Addresses #2547.
2023-05-24 11:33:56 -07:00
Sergio Benitez b6b060f75c Document built-in data guards. 2023-05-18 18:22:40 -07:00
Sergio Benitez 29cd271f8a Only extract needed values in 'async_main'.
Previously, `async_main` would extract a full `Config`. This mean that values
like `address` were read and parsed even when they were unused. Should they
exist and be malformed, a configuration error would needlessly arise.

This commit fixes this by only extract values that are subsequently used.
2023-05-18 17:33:57 -07:00
Sergio Benitez 9f65977b99 Remove closure borrow in 'FromForm' derive.
The codegen for field validations previously included a closure that
could potentially partially borrow a 'Copy' field of the context
structure. To prevent this, 'let'-assign the field before the closure is
created, and use the assignment inside of the closure.
2023-05-15 16:53:26 -07:00
Sergio Benitez f1f533c1e5 Improve and fix panic in 'AdHoc::normalizer()'.
The normalizer now handles more cases.
2023-05-05 11:41:44 -07:00
Sergio Benitez 311a82e3d7 Add 'Error::pretty_print()'. 2023-05-05 11:41:10 -07:00
Sergio Benitez 615e70fdad Log config provenance in debug.
This helps identify configuration issues by printing the source of every
configuration value used by Rocket.
2023-05-04 18:32:27 -07:00
Sergio Benitez db535812b0 Factor out 'Catcher' rank computation. 2023-05-04 18:32:25 -07:00
Sergio Benitez d24b5d4d6d Handle more cases in 'AdHoc::normalizer()'.
The compatibility normalizer previously missed or was overly egregious
in several cases. This commit resolves those issue. In particular:

  * Only request URIs that would not match any route are normalized.

  * Synthetic routes are added to the igniting `Rocket` so that requests
    with URIs of the form `/foo` match routes with URIs of the form
    `/foo/<b..>`, as they did prior to the trailing slash overhaul.

Tests are added for all of these cases.
2023-05-04 17:30:37 -07:00
Sergio Benitez 541952bc58 Paint route URI query parts yellow. 2023-05-04 17:30:23 -07:00
Sergio Benitez c1ead84ec5 Allow 'clippy::style' warnings in attr codegen.
Furthermore, properly forward 'deprecated' items in catcher codegen.
2023-05-04 14:44:38 -07:00
Sergio Benitez 56cf905c6e Introduce more flexible mounting.
Prior to this commit, a route with a URI of `/` could not be mounted in
such a way that the resulting effective URI contained a trailing slash.
This commit changes the semantics of mounting so that mounting such a
route to a mount point with a trailing slash yields an effective URI
with a trailing slash. When mounted to points without a trailing slash,
the effective URI does not have a trailing slash.

This commit also introduces the `Route::rebase()` and
`Catcher::rebase()` methods for easier rebasing of existing routes and
catchers.

Finally, this commit improves logging such that mount points of `/`
are underlined in the logs.

Tests and docs were added and modified as necessary.

Resolves #2533.
2023-05-03 20:03:45 -07:00
Sergio Benitez dbc43c41a3 Fix missing port parsing in 'Authority'.
If a port part was missing, the 'Authority' parser previously set the
port to `0`. This is incorrect. As in RFC#3986 3.2.3:

> URI producers and normalizers should omit the port component and its
  ":" delimiter if port is empty [..]

This commit fixes the parser's behavior to align with the RFC.
2023-05-03 20:03:40 -07:00
Sergio Benitez 6ab85b6643 Remove unnecessary 'mut' in 'uri!' impl. 2023-05-01 17:46:09 -07:00
Sergio Benitez c86da13270 Mark '.exe', '.iso', '.dmg' as known extensions.
'EXE' is IANA registered, and the registered media type is used here for
the '.exe' extension.

The '.iso' and '.dmg' extensions do not appear to correspond to any IANA
registered media type, but they have a de facto media type of
"application/octet-stream", and that media type is used by this commit.

Closes #2530.
2023-05-01 17:25:22 -07:00
Sergio Benitez 9b0564ed27 Tidy custom forward status changes, update docs. 2023-04-11 12:55:57 -07:00
Benedikt Weber 055ad107df Allow status customization in 'Forward' outcomes.
Prior to this commit, all forward outcomes resulted in a 404. This
commit changes request and data guards so that they are able to provide
a `Status` on `Forward` outcomes. The router uses this status, if the
final outcome is to forward, to identify the catcher to invoke.

The net effect is that guards can now customize the status code of a
forward and thus the error catcher invoked if the final outcome of a
request is to forward.

Resolves #1560.
2023-04-11 12:47:20 -07:00
Sergio Benitez b61ac6eb18 Expose 'Route', 'Catcher' collision and matching.
This commit exposes four new methods:

  * `Route::collides_with(&Route)`
  * `Route::matches(&Request)`
  * `Catcher::collides_with(&Catcher)`
  * `Catcher::matches(Status, &Request)`

Each method checks the corresponding condition: whether two routes
collide, whether a route matches a request, whether two catchers
collide, and whether a catcher matches an error arising from a request.

This functionality is used internally by Rocket to make routing
decisions. By exposing these methods, external libraries can use
guaranteed consistent logic to check the same routing conditions.

Resolves #1561.
2023-04-10 22:00:54 -07:00
Sergio Benitez 0c80f7d9e0 Return 'Path' from 'Catcher::base()'. 2023-04-10 13:42:20 -07:00
Sergio Benitez c13a6c6a79 Emit warning when 'String' is used as a parameter.
The warning is only emitted when Rocket is compiled in debug.
2023-04-10 13:38:51 -07:00
Sergio Benitez 3a44b1b28e Hide 'RouteUri' fields to ensure URI coherence.
Prior to this commit, several `RouteUri` fields were public, allowing
those values to be changed at will. These changes were at times not
reflected by the rest of the library, meaning that the values in the
route URI structure for a route became incoherent with the reflected
values. This commit makes all fields private, forcing all changes to go
through methods that can ensure coherence. All values remain accessible
via getter methods.
2023-04-10 13:26:54 -07:00
Sergio Benitez 51ed332127 Make trailing slashes significant during routing.
This commit modifies request routing in a backwards incompatible manner.
The change is summarized as: trailing slashes are now significant and
never transparently disregarded. This has the following implications,
all representing behavior that differs from that before this change:

  * Route URIs with trailing slashes (`/foo/`, `/<a>/`) are legal.
  * A request `/foo/` is routed to route `/foo/` but not `/foo`.
  * Similarly, a request `/bar/` is routed to `/<a>/` but not `/<a>`.
  * A request `/bar/foo` is not routed to `/<a>/<b>/<c..>`.

A new `AdHoc::uri_normalizer()` fairing was added that recovers the
previous behavior.

In addition to the above, the `Options::NormalizeDirs` `FileServer`
option is now enabled by default to remain consistent with the above
changes and reduce breaking changes at the `FileServer` level.
2023-04-10 12:40:39 -07:00
Sergio Benitez 908a918e8b Fuzz to validate routing collision safety.
The fuzzing target introduced in this commit attemps to assert
"collision safety". Formally, this is the property that:

  matches(request, route) := request is matched to route
  collides(route1, route2) := there is a a collision between routes

  forall requests req. !exist routes r1, r2 s.t.
    matches(req, r1) AND matches(req, r2) AND not collides(r1, r2)

Alternatively:

  forall requests req, routes r1, r2.
    matches(req, r1) AND matches(req, r2) => collides(r1, r2)

The target was run for 20 CPU hours without failure.
2023-04-07 20:27:56 -07:00
Sergio Benitez ac0a77bae2 Allow dynamic parameters to match empty segments.
The net effect of this commit is three-fold:

  * A request to `/` now matches `/<a>`. `/foo/` matches `/<a>/<b>`.
  * A segment matched to a dynamic parameter may be empty.
  * A request to `/foo/` no longer matches `/foo` or `/<a>`. Instead,
    such a request would match `/foo/<a>` or `/foo/`.

The `&str` and `String` parameter guards were updated to reflect this
change: they now error, with a newly introduced error type `Empty` in
the `rocket::error` module, when the parameter is empty. As this was the
only built-in parameter guard that would be effected by this change (all
other guards already required nonempty parameters to succeed), the
majority of applications will see no effect as a result.

For applications wanting the previous functionality, a new
`AdHoc::uri_normalizer()` fairing was introduced.
2023-04-07 20:00:09 -07:00
Sergio Benitez 0a56312607 Implement more conservative URI normalization.
* Trailing slashes are now allowed in all normalized URI paths, except
    for route attribute URIs: `/foo/` is considered normalized.
  * Query parts of URIs may now be empty: `/foo?` and `/foo/?` are now
    considered normalized.
  * The `base` field of `Catcher` is now only accessible via a new
    getter method: `Catcher::base()`.
  * `RawStr::split()` returns a `DoubleEndedIterator`.
  * Introduced a second normalization for `Origin`, "nontrailing", and
    associated methods: `Origin::normalize_nontrailing()`, and
    `Origin::is_normalized_nontrailing()`.
  * Added `Origin::has_trailing_slash()`.
  * The `Segments<Path>` iterator will now return an empty string if
    there is a trailing slash in the referenced path.
  * `Segments::len()` is now `Segments::num()`.
  * Added `RawStr::trim()`.

Resolves #2512.
2023-04-07 19:59:57 -07:00
Sergio Benitez a82508b403 Set 'Secure' cookie flag by default under TLS.
If TLS is enabled and active, Rocket will now set the `Secure` cookie
attribute by default.

Resolves #2425.
2023-04-05 13:15:24 -07:00
Sergio Benitez 89534129de Add 'TempFile::open()' to stream its data.
Resolves #2296.
2023-04-05 12:45:48 -07:00
Sergio Benitez 80b7755317 Properly forward 'deprecated' items in codegen.
Resolves #2262.
2023-04-05 11:15:49 -07:00
Sergio Benitez c48ce64a77 Standardize 'response::status' responders.
This commit modifies all of the non-empty responders in the
`response::status` module so that they look like `Status<R>(pub R)`.
Prior to this commit, some responders looked like this, while others
contained an `Option<R>`.

Resolves #2351.
2023-04-05 10:51:05 -07:00
Sergio Benitez 03433c10ea Allow specifying 'Status' in custom form errors.
Resolves #1694.
2023-04-05 09:56:49 -07:00
Sergio Benitez c3520fb4a1 Pin I/O handlers. Allow 'FnOnce' in 'ws' handlers.
This modifies the 'IoHandler::io()' method so that it takes a
'Pin<Box<Self>>', allowing handlers to move internally and assume that
the data is pinned.

The change is then used in the 'ws' contrib crate to allow 'FnOnce'
handlers instead of 'FnMut'. The net effect is that streams, such as
those crated by 'Stream!', are now allowed to move internally.
2023-04-04 15:33:46 -07:00
Sergio Benitez 5e7a75e1a5 Use 'parking_lot' 'Mutex' in fairing's 'Once'. 2023-04-04 15:11:09 -07:00
Sergio Benitez 887558be60 Emit warnings when data limits are reached.
Aid in debugging incorrectly configured data limits.
2023-04-03 13:27:33 -07:00
Sergio Benitez fbb0ace529 Update 'rustls' to 0.21, 'tokio-rustls' to 0.24. 2023-03-31 12:08:45 -07:00