Commit Graph

2431 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 dbeba45b36 Fix testbench ignite test: match new log output. 2024-08-21 02:22:28 -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
Sergio Benitez 327b1ad064 Allow sync drops for 'sync_db_pools' connections.
Prior to this commit, connections from 'sync_db_pools' assumed that they
were being dropped in an async context. This is overwhelmingly the
common case as connections are typically dropped immediately after
request processing. Nothing requires this, however, so holding a
connection beyond the scope of the async context was possible (i.e. by
storing a connection in managed state). Given the connection's `Drop`
impl calls `spawn_blocking`, this resulted in a panic on drop.

This commit resolves the issue by modifying `Drop` so that it calls
`spawn_blocking` only when it is executing inside an async context. If
not, the connection is dropped normally, without `spawn_blocking`.
2024-08-18 20:03:01 -07:00
drawdrop 7fdcf2d1ed Fix various docstring typos.
* unqiue -> unique
  * overriden -> overridden
  * sentinal -> sentinel
2024-08-17 19:37:19 -07:00
Sergio Benitez 2dba18d6f2 Add CONTRIBUTING and update README accordingly. 2024-08-17 19:09:55 -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
Sergio Benitez 2825e46a34 Update 'tokio-tungstenite' to 0.23. 2024-08-16 05:30:45 -07:00
Sergio Benitez e41b5f469e Fix Windows CI: update vcpkg dependency bundle. 2024-08-16 02:24:20 -07:00
Sergio Benitez 6484c62132 Update 'memcache' to 0.17.
We no longer depend on 'r2d2-memcache', which was woefully out of date,
and instead implement our own r2d2 connection manager for memcache.
2024-08-14 18:39:20 -07:00
Sergio Benitez 39c90481e7 Update 'sqlx' to 0.8, 'rusqlite' to 0.31. 2024-08-14 18:39:17 -07:00
Sergio Benitez 628cc2a2f6 Update 'deadpool-{postgres,redis}' to 0.14, 0.16. 2024-08-14 18:39:17 -07:00
Sergio Benitez 87f80714fa Update 'diesel-async' in 'db_pools' to 0.5.
Also modifies the `databases` example so that it makes use of the new
ability to run migrations in diesel-async v0.5. To accomplish this,
`diesel_async::async_connection_wrapper::AsyncConnectionWrapper` is
exported from `rocket_db_pools::diesel` and used in the `diesel_mysql`
portion of the `databases` example. The URL for the MySQL version of the
database example is now `/mysql` instead of `/diesel-async`.
2024-08-14 18:36:56 -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
Sergio Benitez 0998b37aeb Add '--help' flag to testing script. 2024-08-09 22:22:25 -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
Sergio Benitez d4723bb3ee Pin macOS CI 'mysql-client' to '8.4'.
mysqlclient-sys does not recognize v9, which causes the CI to fail. This
resolves the issue.
2024-08-09 01:02:39 -07:00
loikki 38cebebbc3
Derive FromParam for Enum #2826 2024-08-07 22:52:30 -05:00
Flozza 509a033c84
Fix wrong URL in guide (configuration) 2024-08-07 21:36:52 -05:00
Sergio Benitez f2ca2ad735 Add 'RocketDynFmt' subscriber constructor.
Resolves #2840.
2024-08-05 22:24:47 -07:00
Abraham Egnor 4eb6cdf8fb Update 'mongodb' to 3.0. 2024-07-22 15:36:19 -05:00
Alessandro Campeis e2cbcc6e2f Update 'handlebars' to 6.0. 2024-07-22 14:09:21 -05: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
Vadim Anufriev fb4b630405
Add MiniJinja for templating example (#2799)
Update guide to mention MiniJinja.
Adds MiniJinja to the templating example.
2024-06-26 01:27:44 -05: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 606cd61e3f Install NASM on Windows CI job. 2024-06-10 14:47:25 -07: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
Sergio Benitez 5cecc9f0be Detect and handle MessageStream WebSocket closure. 2024-05-31 13:36:32 -05:00
Sergio Benitez abd7335f77 Free more disk space on Linux CI. 2024-05-31 13:36:32 -05:00
Cormac Relf 120d1e78da Generate deterministic names for 'uri' macros. 2024-05-29 15:21:49 -05:00
Sergio Benitez 2a1afd12f5 Add 0.5.1 CHANGELOG entry. 2024-05-23 15:48:35 -05:00
Sergio Benitez 091c6f58f6 Update 'deadpool' and related databases to 0.13. 2024-05-22 19:48:17 -05:00
Arjen cde1fb5de0 Improve example TOML in configuration guide. 2024-05-22 16:52:32 -05:00