Commit Graph

298 Commits

Author SHA1 Message Date
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 b4c8597194 Update UI test expected results. 2023-08-11 15:14:37 -04:00
Sergio Benitez 9a9cd76c01 Add support for 'diesel-async' to 'db_pools'. 2023-06-09 16:47:06 -07:00
Sergio Benitez be92fe648b Update UI tests for latest rustc. 2023-05-25 11:59:46 -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 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 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 6ab85b6643 Remove unnecessary 'mut' in 'uri!' impl. 2023-05-01 17:46:09 -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 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 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 80b7755317 Properly forward 'deprecated' items in codegen.
Resolves #2262.
2023-04-05 11:15:49 -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 219a8a5468 Fix a bunch of typos. 2023-03-23 16:27:08 -07:00
Sergio Benitez 66e2f9486b Update UI tests for 'FromForm' impl addition. 2023-03-23 16:26:48 -07:00
Kian-Meng Ang 06d255b52b Fix a whole bunch of typos.
Found via `codespell -L crate,ser,fo,noo,nd,cappable,pard,te,ans`.
2023-03-23 14:57:54 -07:00
Sergio Benitez 1edfa15d52 Fix several broken rustdoc links. 2023-03-23 14:57:54 -07:00
Sergio Benitez 322f88e61a Update syn, transitively, to 2.0. 2023-03-22 20:11:22 -07:00
Sergio Benitez d628afddd0 Update UI tests for latest rustc. 2023-03-20 14:14:08 -07:00
Sergio Benitez 0c84af2ea7 Update UI test output for latest rustc. 2023-03-08 10:45:25 -08:00
Jason Hinch 910994f982 Fix Result namespacing in FromFormField derive.
Previously, if a module used or defined a type alias for Result,
FromFormField derives would fail to compile as it would use the type
alias instead of the fully qualified type.
2023-01-31 11:19:57 -08:00
Sergio Benitez e468a98333 Update UI tests for latest stable, nightly. 2023-01-30 16:10:59 -08:00
Sergio Benitez ca4b38c0d0 Allow UI tests to fail in CI.
This commit makes passing compile UI tests optional, allowing the CI to
succeed even when UI tests fail. This change was made because UI tests
are highly susceptible to false negatives due to benign rustc compiler
output changes. A failure resulting from such a benign change inhibits
progress in the main branch due to failing PR testing which would have
otherwise passed.
2023-01-30 16:06:18 -08:00
Sergio Benitez 162fafa0f1 Update UI tests for nightly. 2022-11-18 19:30:35 -08:00
Sergio Benitez 7e913eb8ac Report as many form errors as possible. 2022-11-12 04:11:18 -08:00
Sergio Benitez 8166ad0c7c Fix error field names in 'FromForm' derive.
Prior to this commit, the `FromForm` derive could pair the incorrect
field name with a failing validation. The bug was caused by using two
mismatched iterators in a `quote!()` invocation. Specifically, the first
iterator emitted validation calls for all fields that had validation
applied, while the second emitted field names for all fields,
irrespective of whether the field had any validation applied. The two
iterators were effectively zipped to create the final error, creating
the bug.

This commit fixes the issue by correctly matching field names with their
validators at the expense of an additional allocation, necessitated by
the `quote` crate's inability to access subfields in a repetition.

Fixes #2394.
2022-11-11 18:20:06 -08:00
Bonex 440a88ad27 Add failing form validation test cases. 2022-11-11 18:19:43 -08:00
Sergio Benitez cd23885ee3 Update UI tests for latest nightly. 2022-11-11 18:19:33 -08:00
Sergio Benitez f10a2d7d9c Include stable rust-src diagnostics. 2022-09-01 01:47:02 -07:00
Sergio Benitez 13732f8a6b Update UI tests for latest nightly, stable. 2022-08-31 13:52:40 -07:00
Sergio Benitez 8d8367e32b Update UI tests for latest nightly, stable. 2022-07-13 18:23:39 -07:00
pennae 7275df9fdf Make data guards eligible to be sentinels.
Prior to this commit, data guards were not being considered as eligible
to be sentinels. This commit resolves that.
2022-06-23 16:15:11 -07:00
Sergio Benitez 6e5568a155 Update UI tests for latest nightly. 2022-06-21 00:13:14 -07:00
Sergio Benitez 30b8a77fc9 Avoid dropping 'Error' inside '#[launch]' future.
Due to tokio-rs/tokio#4780, a panicking top-level future combined with
an uncooperative background task prevents runtime shutdown. To avoid
this in the case of `Rocket::launch()` returning an `Error`, which
panics on drop if it isn't inspected, we return the `Result` to the
caller (i.e., `main`) instead of the `block_on` future. This prevent the
panic from occuring inside of the `block_on` future and so the runtime
terminates even with uncooperative I/O.
2022-06-20 23:49:41 -07:00
Konrad Borowski 6f223518e4 Fix 'clippy::needless_late_init' in form codegen.
Changes codegen for '#[field(default = e)]' to resolve the
'needless_late_init' Clippy warning.
2022-05-23 16:41:10 -07:00
Sergio Benitez d92b7249cb Update UI tests for latest stable rustc. 2022-05-19 14:16:05 -07:00
Konrad Borowski e390423083 Enable 'cookie' 'secure' feature conditionally.
This was incorrectly enabled unconditionally in 442b668.
2022-05-18 17:29:52 -07:00
Sergio Benitez bf2bd0e9ed Impl 'Responder' for 'Box<T: Responder + Sized>'.
In other words, allow boxing sized responders.

Resolves #1999.
2022-05-10 15:48:40 -05: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
Sergio Benitez 0ba56ccbb3 Revamp shutdown to recover shutdown 'Rocket'.
The core improvement is that `Rocket::launch()` now resolves to
`Ok(Rocket<Ignite>)` on nominal shutdown. Furthermore, shutdown never
terminates the running process.

Other changes directly related to shutdown:

  * Runtime worker thread names are now irrelevant to graceful shutdown.
  * `ErrorKind::Runtime` was removed; `ErrorKind::Shutdown` was added.
  * The `force` config value is only read from the default provider.
  * If `force`, Rocket's constructed async runtime is terminated.

Other related changes:

  * The exported `hyper` module docs properly reflect public re-exports.
2022-05-07 06:12:24 -05:00
Sergio Benitez 4c6c0b497c Avoid more platform dependent errors in UI tests. 2022-05-03 14:33:11 -07:00
Sergio Benitez 55ea5dfb35 Avoid platform dependent errors in UI tests. 2022-05-03 13:56:25 -07:00
Sergio Benitez 613366f4bb Fix UI tests. 2022-04-27 13:59:20 -07:00
Sergio Benitez 6bdd2f8186 Consider form parsing strategy for 'Vec', 'Map'.
Prior to this commit, 'Vec', 'HashMap', and 'BTreeMap' would parse
leniently irrespetive of the requested parsing strategy. This commit
changes their behavior so that the parsing strategy is respected.

Resolves #2131.
2022-04-21 08:17:58 -07:00
Konrad Borowski 4d258739f5 Migrate Rocket to Rust 2021 edition. 2022-04-19 18:35:38 -07:00
Sergio Benitez bc2315943b Allow 'unused_doc_comments' on generated doctests. 2022-04-19 13:13:33 -07:00