Commit Graph

926 Commits

Author SHA1 Message Date
Sergio Benitez 9496b70e8c Strip body and content-length on 204, body on 304.
This works-around an issue where hyper incorrectly removes the body on
204 responses without removing the content-length or setting it to zero.

Resolves #2821.
2024-08-23 16:18:48 -07:00
Sergio Benitez d3323391ab Add fairing retrieval methods to 'Rocket'.
Introduces four new methods:

  * `Rocket::fairing::<F>()`
  * `Rocket::fairing_mut::<F>()`
  * `Rocket::fairings::<F>()`
  * `Rocket::fairings_mut::<F>()`

These methods allow retrieving references to fairings of type `F` from
an instance of `Rocket`. The `fairing` and `fairing_mut` methods return
a (mutable) reference to the first attached fairing of type `F`, while
the `fairings` and `fairings_mut` methods return an iterator over
(mutable) references to all attached fairings of type `F`.

Co-authored-by: Matthew Pomes <matthew.pomes@pm.me>
2024-08-21 16:42:09 -07:00
Sergio Benitez e889c2628a Improve ignite fairing failure trace message. 2024-08-20 23:32:04 -07:00
Wojciech Polak 8b9d906cc4 Derive equality, ordering traits for http::Status.
`PartialEq` when not derived results in `StructuralPartialEq` not being
implemented. As this was the case for `http::Status`, matching against
constants like `Status::Unauthorized` was not allowed.

This commit replaces the manual implementations of equality traits
(`PartialEq`, `Eq`) and ordering traits (`PartialOrd`, `Ord`) for
`http::Status` with `#[derive]`.

Resolves #2844.
2024-08-19 15:52:44 -07:00
drawdrop 7fdcf2d1ed Fix various docstring typos.
* unqiue -> unique
  * overriden -> overridden
  * sentinal -> sentinel
2024-08-17 19:37:19 -07:00
Sergio Benitez ef1cfa0965 Impl 'TryFrom<&str>' for 'Method'.
Also implements 'From<Infallible>' for 'ParseMethodError'.
2024-08-17 04:26:18 -07:00
lobsterwise 4c71ed6ee3 Fix support for HTTP extension methods. 2024-08-17 04:25:49 -07:00
Sergio Benitez 51d4ed4394 Update 'h3' and 's2n_quic' dependencies. 2024-08-16 16:12:12 -07:00
Sergio Benitez faa0543c3d Pin 's2n-quic-h3' git dependency to a commit. 2024-08-16 15:47:04 -07:00
Matthew Pomes 1a3ef5b23f
Update docs to make sense 2024-08-10 13:02:41 -05:00
Sergio Benitez 39ed4a4909 Enforce using 'MsgPack<T>' to deserialize.
This commit enforces using 'MsgPack<T>', and not 'MsgPack<T, Foo>' or
'Compact<T>', to deserialize MsgPack-encoded data. It also simplifies
the round-trip msgpack test and removes the dev-dependency on `rmp`.
2024-08-09 23:10:33 -07:00
Matthew Pomes db598be3a8
Change default, and use `MsgPack` in place of `Named` 2024-08-09 23:13:53 -05:00
Artemis df71f79bd9
Allow responding with named MessagePack data.
Closes #2107
2024-08-09 23:13:52 -05:00
Sergio Benitez 1f82d4bbcd Improve `FromParam` derive docs and error values.
This commit improves the docs for the `FromParam` derive macro and
exposes a new `InvalidOption` error value, which is returned when the
derived `FromParam` implementation fails.
2024-08-09 18:44:50 -07:00
Sergio Benitez 15062ded09 Update UI tests for latest rustc. 2024-08-09 18:34:59 -07:00
loikki 38cebebbc3
Derive FromParam for Enum #2826 2024-08-07 22:52:30 -05:00
Sergio Benitez f2ca2ad735 Add 'RocketDynFmt' subscriber constructor.
Resolves #2840.
2024-08-05 22:24:47 -07:00
Sergio Benitez f50b6043e8 Improve FileServer rewrite API.
Finalizes the FileServer rewrite API implementation. Primarily reworks
how the built-in rewriters are written (now as structs instead of free
functions) and reorganizes the `fs` module.

Co-authored-by: Matthew Pomes <matthew.pomes@pm.me>
2024-07-06 15:34:21 +02:00
Matthew Pomes 65e3b87d6b Implement FileServer rewrite API.
Implements the FileServer API proposed in
https://github.com/rwf2/Rocket/pull/2716#issuecomment-1930893889.

Closes #2716.
2024-07-06 15:33:43 +02:00
Matthew Pomes 6857b82ec4 Use codegen event target prefix 'rocket::codegen'.
This commit prefixes the target of all trace events emitted by codegen
with `rocket::codegen::{kind}::{module_path!()}`, where `kind` is the
kind of codegen item that was generated (i.e, `route`). This increases
the consistency of trace messages emitted by Rocket so that they all
begin with 'rocket::'.
2024-06-10 19:56:37 -05:00
Sergio Benitez 4a00c1fe77 Improve 'Error' type: make 'ErrorKind' accessible.
This commit improves the 'Error' type such that:
  - It is now fully documented.
  - The `ErrorKind` enum variant fields are all publicly reachable.
  - The `Sentry` type is exposed.

This is a breaking change:
  - `ErrorKind::Collisions` is now struct-like with two fields.
2024-06-03 20:11:20 -07:00
Sergio Benitez 926e06ef3c Finalize 'tracing' migration.
This commit complete the migration to 'tracing' for all logging. Below
is a summary of all relevant commits, including this one:

Log improvements:
  - All log (trace) messages are structured which means they contain fields
    that can formatted by any subscriber.
  - Logging can be disabled entirely by disabling the default `trace` feature.
  - Routes and catchers now contain location (file/line) information.
  - Two log format kinds: pretty and compact via ROCKET_LOG_FORMAT
  - Coloring is not disabled globally. Thus applications can color even if
    Rocket is configured not to.
  - Rocket is more conservative about 'warn' and 'error' messages, reserving
    those log levels for messages useful in production.
  - Errors from guards logged by codegen now use the 'Display' implementation of
    those errors when one exists.
  - Secrets are never logged, even when directly asked for.

New features:
  - Many Rocket types know how to trace themselves via a new `Trace` trait.
  - `Either` types can now be used in `uri!()` calls.
  - A `RequestIdLayer` tags all requests with a unique ID.

Breaking changes to configuration:
  - `Config::log_level` is of type `Option<Level>`. `None` disables tracing.
  - `log_level` now uses the traditional log level names: "off", "error",
    "warn", "info", "debug", "trace", or 0-5. This replace the Rocket-specific
    "normal", "debug", "critical".
  - A new option, `log_format`, which is either `compact` or `pretty`,
    determines how Rocket's tracing subscriber log trace messages.

Breaking changes:
  - Hidden `rocket::Either` is now publicly available at `rocket::either::Either`.
  - `rocket::Error` no longer panics when dropped.
  - `main` generated by `#[launch]` returns an `ExitCode`.
  - `FromParam` `Err` now always returns the actual error as opposed to the
    string that failed to parse. To recover the original string, use `Either<T,
    &str>`, where `T: FromParam`, as a parameter guard.
  - Many types that implemented `Display` now instead implement `Trace`.
  - `Error::pretty_print()` was removed. Use `Error::trace()` via `Trace` impl.

Internal improvements:
  - Made more space in CI machines for tasks.
  - Cleaned up testbench code using `inventory`.

Resolves #21.
2024-06-03 15:02:44 -07:00
Sergio Benitez 45264de8c9 Allow dynamic selection of log format. 2024-06-03 14:39:20 -07:00
Sergio Benitez cc2b159e85 Document the new 'trace' feature. 2024-06-03 14:39:12 -07:00
Sergio Benitez b12b7f27d7 Remove old 'log' macros. Color via subscriber.
This commit:
  - Removes painting outside trace subscriber in core.
  - Removes all non-subscriber uses of yansi.
  - Removes all uses of old log macros.
  - Fix trace exports.
2024-06-03 14:39:12 -07:00
Sergio Benitez d767694861 Remove 'Error' panic-on-drop behavior.
Instead, the `#[launch]` attribute traces the error and panics,
replicating the old behavior in the common case.
2024-06-03 14:38:34 -07:00
Sergio Benitez 8a1c91b7d5 Implement 'Trace' trait. Use structured logging.
This commit:
  - Converts most log messages into structured messages.
  - Implements an initial request ID layer.
  - Implements pretty and compact loggers.
2024-06-03 14:33:24 -07:00
Sergio Benitez ff6da900a0 Migrate to 'tracing' for logging.
This commit:
  - Remove all traces of 'log'.
  - Send all logs unedited via tracing.
  - Parses and propagate log_level.
  - Implements an initial formatting subscriber.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
2024-06-03 14:32:01 -07:00
Cormac Relf 120d1e78da Generate deterministic names for 'uri' macros. 2024-05-29 15:21:49 -05:00
Bill 35a100fdec Remove double semicolon in SSE example 2024-05-22 14:38:20 -05:00
Sergio Benitez 3079dbfa85 Use workspace lints. Resolve new nightly warnings. 2024-05-20 13:39:14 -05:00
Sergio Benitez bb48a4d724 Fix 'since' version in 'deprecated' attribute. 2024-05-07 02:18:27 -07:00
Sergio Benitez 370287c9a6 Fix 'TcpListener' port required regression. 2024-05-03 17:17:56 -07:00
Sergio Benitez 5f9ff3f3af Impl 'FromForm' for char, 'Range' types.
Implements 'FromForm' for:

  * `char`
  * `Range<T: FromForm>`
  * `RangeFrom<T: FromForm>`
  * `RangeTo<T: FromForm>`
  * `RangeToInclusive<T: FromForm>`

Resolves #2759.
2024-05-02 16:18:53 -07:00
Sergio Benitez fd2094c5f3 Use call site hygiene in FromForm derive.
This commit changes the `FromForm` derive codegen so that it
consistently emits tokens with call site hygiene. This allows `FromForm`
derives to be emitted my macros more reliably.
2024-05-02 16:18:51 -07:00
Sergio Benitez 7b17de6699 Improve 'sync_db_pools' codegen. Update UI tests. 2024-05-02 16:16:00 -07:00
Sergio Benitez e6aaea072c Use 'dep' syntax for 'http' features. 2024-04-26 01:42:33 -07:00
Sergio Benitez 836e64fec3 Rename 'Rocket::configure()' to 'reconfigure()'. 2024-04-25 14:47:43 -07:00
Sergio Benitez b34085392d Add 'Method' variants for all registered methods.
This commit allow routes to be declared for methods outside of the
standard HTTP method set. Specifically, it enables declaring routes for
any method in the IANA Method Registry:

```rust
#[route(LINK, uri = "/<foo>")]
fn link() { ... }

#[route("VERSION-CONTROL", uri = "/<foo>")]
fn version_control() { ... }
```

The `Method` type has gained variants for each registered method.

Breaking changes:

  - `Method::from_str()` no longer parses mixed-case method names.
  - `Method` is marked as non-exhaustive.
  - `Method::supports_payload()` removed in favor of
    `Method::allows_request_body()`.

Resolves #232.
2024-04-24 19:22:03 -07:00
Sergio Benitez 85ca2bc01c Refactor internal ignite sequencing. 2024-04-22 17:27:01 -07:00
Sergio Benitez 3bfc4ca644 Simplify 'Bind'. Allow try-launching on Futures. 2024-04-22 17:26:51 -07:00
Sergio Benitez 7cc818cd85 Introduce dynamic TLS resolvers.
This commit introduces the ability to dynamically select a TLS
configuration based on the client's TLS hello via the new `Resolver`
trait. In support of this, it also makes the following changes:

  * Added `Authority::set_port()`.
  * `UdsListener` is now `UnixListener`.
  * `Bindable` removed in favor of new `Bind`.
  * All built-in listeners now implement `Bind<&Rocket>`.
  * `Connection` requires `AsyncRead + AsyncWrite`.
  * The `Debug` impl for `Endpoint` displays the underlying address.
  * `Listener` must be `Sized`.
  * The TLS listener was moved to `tls::TlsListener`.
  * The preview `quic` listener no longer implements `Listener`.
  * Added `TlsConfig::server_config()`.
  * Added `race` future helpers.
  * Added `Rocket::launch_with()`, `Rocket::bind_launch()`.
  * Added a default `client.pem` to the TLS example.
  * Various unnecessary listener `Config` structures removed.

In addition, the testbench was revamped to support more scenarios. This
resulted in the following issues being found and fixed:

  * Fix an issue where the logger would ignore color requests.
  * Clarified docs for `mtls::Certificate` guard.
  * Improved error messages on listener misconfiguration.

Resolves #2730.
Resolves #2363.
Closes #2748.
Closes #2683.
Closes #2577.
2024-04-16 23:50:28 -07:00
Sergio Benitez 60f3cd57b0 Add end-to-end testbench.
Resolves #1509.
2024-04-12 03:15:44 -07:00
Rong "Mantle" Bao ff12b1d4bc Update allowed lints for MSRV of 1.75. 2024-04-11 18:13:37 -07:00
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