Commit Graph

49 Commits

Author SHA1 Message Date
Alessandro Campeis e2cbcc6e2f Update 'handlebars' to 6.0. 2024-07-22 14:09:21 -05: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
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 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 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 9e3f9ae00f Update 'minijinja' to 2.0. 2024-05-22 15:03:18 -05:00
Michael Melanson 347d9da663 Improve minijinja and tera template error logs. 2024-05-22 14:46:03 -05:00
Sergio Benitez 3079dbfa85 Use workspace lints. Resolve new nightly warnings. 2024-05-20 13:39:14 -05: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
Łukasz Wojniłowicz a742d3da4f Symlink license files in all crate directories.
Resolves #2760.
2024-04-06 20:46:07 -07:00
Sergio Benitez 8614a7fece Support minijinja in 'dyn_templates'. 2024-04-03 14:54:01 -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 38dbab8dd3 Bump MSRV to 1.75 for `async fn` in traits. 2024-01-30 09:18:43 -08:00
Sergio Benitez 5034ff0d1a Update handlebars version in dyn_templates docs. 2024-01-17 21:41:25 -08:00
Alessandro Campeis dca3afcd77 Update 'handlebars' to v5.1. 2024-01-17 21:41:25 -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 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 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 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 ed5c755bb6 Avoid using 'glob' to walk templates directory.
Previously, `dyn_templates` walked the user-provided `template_dir` path by
constructing a glob pattern prefixed with `template_dir`. If `template_dir`
contained characters recognized by the glob pattern parser, then at best the
pattern failed to parse, and at worst, incorrect directories were searched.

This commit removes the use of `glob` to walk the templates directory and
instead uses `walkdir`, obviating the issues described above.

Fixes #2627.
2023-10-14 15:00:36 -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 c2936fcb1e Update 'yansi' to 1.0.0-rc. 2023-07-11 13:18:35 -07:00
Sergio Benitez 91f6288ea4 New version: 0.5.0-rc.3.
New contrib versions: 0.1.0-rc.3.
2023-03-23 16:56:17 -07:00
Sergio Benitez bbbb927ac2 Update dependencies without observable breakages.
The following dependencies were updated:
  * `criterion` from 0.3 to 0.4
  * `deadpool-redis` from 0.10 to 0.11
  * `normpath` from 0.3 to 1
  * `cookie` from 0.16 to 0.17
2023-03-22 13:44:16 -07:00
Jacob Simpson 6c3d35e7e5 Update notify to 5.0.
Resolves #2337.
2022-09-18 01:49:15 -07:00
Sergio Benitez 9b3c83eb70 Add 'Metadata::render()': direct template render.
Resolves #1177.
2022-05-20 16:18:17 -07:00
Sergio Benitez 4dcd92837f New version: 0.5.0-rc.2.
New contrib versions: 0.1.0-rc.2.
2022-05-09 06:32:46 -05:00
Konrad Borowski 4d258739f5 Migrate Rocket to Rust 2021 edition. 2022-04-19 18:35:38 -07:00
Juraj Fiala 71e96d0d0d Fix typo: 'Tera' -> 'Handlebars'. 2022-03-03 15:48:00 -08:00
Sergio Benitez b5b842f0bf Use fully working examples in dyn_templates.
Closes #1992.
2022-03-03 15:41:29 -08:00
Gabriel Fontes 66d18bf665 Explicitly import 'Result' in 'context!'. 2022-02-17 16:33:36 -08:00
Sergio Benitez 9bc6c25d2d Fix docs for handlebars update. 2021-08-30 03:44:08 -07:00
Ning Sun 831ffc6c09 Update 'handlebars' to 4.0. 2021-08-30 03:42:57 -07:00
Sergio Benitez bb920e6e09 Fix 'context!()' typo: "supports" -> "supported". 2021-07-02 11:44:53 -07:00
Dominik Boehi d671ec5bb5 Fix link to 'rocket_dyn_templates' git repository. 2021-06-30 10:14:58 -07:00
Flying-Toast 8e3ad40beb Add 'context!' for ad-hoc templating contexts. 2021-06-30 10:09:28 -07:00
Sergio Benitez 0b2fcb9f4b Use Figment's 'Value' in contrib templating.
Previously, 'serde_json::Value' was used to store the serialized
template context. This value does not represent all of serde's data
model. This means we may fail to serialize a valid Rust value into it,
for instance, 128-bit integers. This is reduced with Figment's 'Value',
which supports the majority if not all of the serde data model.

At present, all supported templating engines use 'serde_json::Value', so
in practice, this commit has no effect but to reduce local dependencies
and provide better error messages for bad contexts.
2021-06-25 09:08:49 -07:00
Sergio Benitez c028d63e5b New version: 0.5.0-rc.1.
New contrib versions: 0.1.0-rc.1.
2021-06-09 09:52:37 -07:00
Sergio Benitez 6961a717d8 Use crates.io compatible internal package names. 2021-06-09 09:47:21 -07:00
Sergio Benitez 394982edbd Make new contrib libraries publishable. 2021-06-09 04:51:46 -07:00
Sergio Benitez 4c6562cd29 Drop 'Data' after sending a response, not before.
This allows responses to be sent to the client even when data is only
partially read, significantly improving the experience for the client
from one with a "connection closed" error to one with a proper response.
The consequence is a lifetime in 'Data'.

Though other non-lifetime-introducing solutions exist, the introduction
of a lifetime to 'Data' is a longstanding desire as it prevents
smuggling 'Data' into a longer-lived context. Use of 'Data' in that
context was unspecified with various runtime consequences. The addition
of a lifetime bound by the request prevents this error statically.

In summary, the changes are:
  * Clients receive responses even when data isn't fully read.
  * 'Data' becomes 'Data<'r>'. 'FromData' changes accordingly.
  * Route 'Outcome's are strictly tied to the request lifetime.

Tangentially, the invalid length form field validation error message has
improved to format length in byte units if it exceeds 1024.
2021-06-08 13:26:16 -07:00
Sergio Benitez 0aa9a11ca4 Fix typos throughout codebase. 2021-06-07 19:31:21 -07:00
Sergio Benitez 735bd99549 Update 'normpath' to 0.3. 2021-05-29 15:33:15 -07:00
Sergio Benitez 02d6c4c6f1 Remove 'default-features' from contrib examples. 2021-05-25 05:28:58 -07:00
Sergio Benitez 5a4e66ec43 Split 'rocket_contrib' into distinct crates.
This follows the completed graduation of stable contrib features into
core, removing 'rocket_contrib' in its entirety in favor of two new
crates. These crates are versioned independently of Rocket's core
libraries, allowing upgrades to dependencies without consideration for
versions in core libraries.

'rocket_dyn_templates' replaces the contrib 'templates' features. While
largely a 1-to-1 copy, it makes the following changes:

  * the 'tera_templates' feature is now 'tera'
  * the 'handlebars_templates' feature is now 'handlebars'
  * fails to compile if neither 'tera' nor 'handlebars' is enabled

'rocket_sync_db_pools' replaces the contrib 'database' features. It
makes no changes to the replaced features except that the `database`
attribute is properly documented at the crate root.
2021-05-24 22:57:51 -07:00