Commit Graph

1863 Commits

Author SHA1 Message Date
Sergio Benitez
20605dac14 Set default route rank using "colorings".
This new system colors paths and queries in one of three ways:

  1. `static`, meaning all components are static
  2. `partial`, meaning at least one component is dynamic
  3. `wild`, meaning all components are dynamic

Static paths carry more weight than static queries. The same is true for
partial and wild paths. This results in the following default rankings:

| path    | query   | rank |
|---------|---------|------|
| static  | static  | -12  |
| static  | partial | -11  |
| static  | wild    | -10  |
| static  | none    | -9   |
| partial | static  | -8   |
| partial | partial | -7   |
| partial | wild    | -6   |
| partial | none    | -5   |
| wild    | static  | -4   |
| wild    | partial | -3   |
| wild    | wild    | -2   |
| wild    | none    | -1   |
2021-03-26 19:41:00 -07:00
Sergio Benitez
ec1ccc248c Test 'Limits::{find,get}' with tri-level limits. 2021-03-25 18:52:04 -07:00
Sergio Benitez
630a458417 Expose active 'Rocket' via 'Request::rocket()'. 2021-03-25 18:33:15 -07:00
Sergio Benitez
9cb2552055 Inline a few more 'Request' methods. 2021-03-25 18:19:34 -07:00
Sergio Benitez
af598fb872 Use concrete lifetime in 'Request::uri()'. 2021-03-25 18:17:51 -07:00
Sergio Benitez
4741ae0787 Fix minor typo in requests guide. 2021-03-25 18:06:12 -07:00
Sergio Benitez
e7934a2a3f Parse inner form 'T' in 'Option<T>' strictly.
This behavior more closely matches the expectation that a missing field
results in 'None'.

Also cleans up forms docs for readability, completeness.
2021-03-24 19:53:13 -07:00
Sergio Benitez
33790254f1 Store full '&Rocket' in '&Request'.
This is instead of storing pieces of the active Rocket instance.
2021-03-24 11:59:23 -07:00
Sergio Benitez
81346e5949 Don't expose hidden 'Route' collider methods. 2021-03-20 03:04:31 -07:00
Sergio Benitez
b3021e2acb Fix all broken links. Update some outdated docs. 2021-03-19 18:09:13 -07:00
Sergio Benitez
def9b4dcd2 Always emit 'Request<'_>', with lifetime. 2021-03-19 18:05:27 -07:00
Sergio Benitez
84fda62678 Emit query parse code only when there's a query. 2021-03-19 18:04:28 -07:00
Sergio Benitez
8749d7293a Simplify and optimize router.
This surfaced a dormant concurrency related issue. Prior to this commit,
the router used `routed_segments()` to retrieve the path segments of the
request. This was okay as there was no route in the request, and matched
segments were retrieved eagerly.

This commit makes segment matching lazy, so no matching occurs if
unnecessary. Between two matches, a `route` is atomically set of
`Request`. This is now visible in `routed_segments()`, which should not
have considered the current route in the first place. This was fixed.
2021-03-19 03:49:58 -07:00
Sergio Benitez
39d7931d6a Expose 'router' module, document 'RouteUri'. 2021-03-19 03:49:58 -07:00
Ben Sully
97acd8d9a9 Update tests and docstrings for 'RouteUri'. 2021-03-19 03:49:58 -07:00
Sergio Benitez
2463637d51 Introduce 'RouteUri'.
Co-authored-by: Ben Sully <ben@bsull.io>
2021-03-19 03:49:54 -07:00
Sergio Benitez
487485d108 Explicitly specify 'template_dir' in forms example. 2021-03-17 18:34:05 -07:00
Sergio Benitez
b24e53454a Generate CA cert in 'gen_certs.sh'. 2021-03-17 18:25:06 -07:00
Abdullah Alyan
af48d1f2e6 Support more TLS key types in PKCS format.
Closes #1449.
Resolves #1461.
2021-03-17 18:23:15 -07:00
Sergio Benitez
f254504dc9 Depend on a single revision of 'state'.
Closes #1577.
2021-03-15 02:46:34 -07:00
Sergio Benitez
1b2edd38b3 Clarify 'TempFile' configuration parameters. 2021-03-15 02:43:01 -07:00
Sergio Benitez
f9d4a78fbb Fix spacing in 'Route::default_rank()'. 2021-03-15 02:39:21 -07:00
Sergio Benitez
9c678e606b Track and log catcher names. 2021-03-15 02:27:53 -07:00
Sergio Benitez
304e65ac72 Catch panics that occur before future is returned.
In the course of resolving this issue, double-boxing of handlers was
discovered and removed.
2021-03-15 02:20:48 -07:00
Sergio Benitez
70b42e6f0e Remove second lifetime from 'FromRequest'.
While offering some utility, the lifetime did not carry its weight, and
in practice offered no further ability to borrow. This greatly
simplifies request guard implementations.
2021-03-14 19:57:59 -07:00
Sergio Benitez
2366bff05f Rearrange contrib database support modules. 2021-03-12 15:44:19 -08:00
Sergio Benitez
4b09e77ccb Decrease lock period while reloading templates.
Previously, an `rx` lock was held for the entirety of the check period,
effectively making request handling serial. The implementation also held
a `write` lock to templating context while an expensive user-callback
was called, limiting template-related concurrency during that period.
This was changed so no lock is held during that period and a write-lock
is held only for the duration of the context field write.
2021-03-11 02:55:38 -08:00
Sergio Benitez
e532f4e2b3 Disallow defaults in strict forms.
Partially resolves #1536.
2021-03-11 02:03:13 -08:00
Sergio Benitez
ef7b7a953e Improve forms guide. 2021-03-11 01:12:20 -08:00
Sergio Benitez
8283bf0a2b Make obvious when and which tests in '--all' fail. 2021-03-10 22:52:37 -08:00
Sergio Benitez
f483edaafb Remove unused imports in fairings test. 2021-03-10 22:30:23 -08:00
Sergio Benitez
c0caa3b874 Fix codegen doctests for 'Route.name' changes. 2021-03-10 22:28:06 -08:00
Sergio Benitez
a0e4c9677c Allow dynamic route names. Log 'StaticFiles' root. 2021-03-10 18:40:38 -08:00
Sergio Benitez
191b93498e Remove boxed futures in server, use async fn. 2021-03-10 16:31:32 -08:00
Sergio Benitez
88cb6ec4d1 Always test on stable on publish. 2021-03-10 14:56:34 -08:00
Sergio Benitez
015438a780 Print config on attach in config example. 2021-03-10 03:37:03 -08:00
Sergio Benitez
3c25326917 Log only non-empty fairing classes. 2021-03-10 02:30:13 -08:00
Sergio Benitez
497c4765f2 Fix typo in 'Rocket::ignite()' docs. 2021-03-10 02:16:59 -08:00
Sergio Benitez
bc38196f8d Generate a secret key in debug only if it is zero.
This prevents printing a secret key warning if a secret key was
generated, as is done by Rocket itself. This does not change any
behaviors in non-debug profiles.
2021-03-10 02:13:50 -08:00
Sergio Benitez
c9d7b4fbe0 Use '-Zrustdoc-map' to fill in external doc URLs. 2021-03-09 22:00:52 -08:00
Sergio Benitez
ab3413826c Improve fairing example. 2021-03-09 21:57:30 -08:00
Sergio Benitez
cce9ea1e1e Cache dependencies in CI, cleanup job matrix. 2021-03-09 21:57:30 -08:00
Sergio Benitez
17dd8dafd0 Move examples to their own workspace.
This allows us to test all of the "core" crates (and the guide) by
testing the root workspace, and all of the examples by testing in the
examples workspace.
2021-03-09 21:57:30 -08:00
Sergio Benitez
4e06ee64aa Test 'secret_key' validation, now on pre-launch.
Prior to this commit, it was not possible to test Rocket crates in
production mode without setting a global secret key or bypassing secret
key checking - the testing script did the latter. The consequence is
that it became impossible to test secret key related failures because
the tests passed regardless.

This commit undoes this. As a consequence, all tests are now aware of
the difference between debug and release configurations, the latter of
which validates 'secret_key' by default. New 'Client::debug()' and
'Client::debug_with()' simplify creating an instance of 'Client' with
configuration in debug mode to avoid undesired test failures.

The summary of changes in this commit are:

  * Config 'secret_key' success and failure are now tested.
  * 'secret_key' validation was moved to pre-launch from 'Config:from()'.
  * 'Config::from()' only extracts the config.
  * Added 'Config::try_from()' for non-panicking extraction.
  * 'Config' now knows the profile it was extracted from.
  * The 'Config' provider sets a profile of 'Config.profile'.
  * 'Rocket', 'Client', 'Fairings', implement 'Debug'.
  * 'fairing::Info' implements 'Copy', 'Clone'.
  * 'Fairings' keeps track of, logs attach fairings.
  * 'Rocket::reconfigure()' was added to allow modifying a config.

Internally, the testing script was refactored to properly test the
codebase with the new changes. In particular, it no longer sets a rustc
'cfg' to avoid secret-key checking.

Resolves #1543.
Fixes #1564.
2021-03-09 21:57:26 -08:00
Sergio Benitez
bbbe362740 Indirectly use 'Uuid::Error' for backwards compat.
Closes #1565.
2021-03-09 21:57:25 -08:00
Sergio Benitez
fd8af3a2c5 Pass extra testing script flags as cargo flags. 2021-03-09 21:57:03 -08:00
Sergio Benitez
83ffe0f7bc Remove 'Config::profile()'. CFG 'secret_key' field.
This commit makes the `Config.secret_key` conditionally compile on the
`secrets` feature. The net effect is simplified internal code, fewer
corner-cases, and easier to write tests.

This commit removes the `Provider::profile()` implementation of
`Config`. This means that the `Config` provider no longer sets a
profile, a likely confusing behavior. The `Config::figment()` continues
to function as before.
2021-03-09 21:40:53 -08:00
Sergio Benitez
f454895023 Fix small typo in contrib 'Uuid' docs. 2021-03-06 03:48:51 -08:00
Jeb Rosen
d778c2cb10 Drop embedded async 'Client' in async runtime. 2021-03-06 01:40:43 -08:00
Sergio Benitez
68b244ebdc Forward catcher, handler failure to 500 catcher.
This changes core routing so that panics in all handlers are handled by
emitting a long message explaining that panics are bad and invoking the
500 error catcher. If the 500 error catcher fails, Rocket's default 500
catcher is used.
2021-03-06 01:39:31 -08:00