Commit Graph

587 Commits

Author SHA1 Message Date
Rodolphe Bréard 7a54a1293e Display launch address using 'SocketAddr' fmt.
This fixes IPv6 address display and future-proofs any such display.
2021-08-24 19:40:42 -07:00
Sergio Benitez dd43d68d28 Use cardinality-agnostic wording in error format.
Closes #1746.
2021-08-24 19:39:42 -07:00
Sergio Benitez 3616f25c0b Update 'time' to 0.3, 'cookie' to 0.16.
Also reexport 'time' from the crate root.
2021-08-19 19:49:23 -07:00
Sergio Benitez 80cd30086a Don't enable unused 'futures' features. 2021-08-19 19:49:23 -07:00
Sergio Benitez a16c66eae9 Propagate 'log_level' to SQLx logs.
Closes #1798.
2021-08-19 19:49:20 -07:00
Sergio Benitez a7f6fb2363 Track caller in 'mount' and 'register' calls. 2021-08-19 19:43:34 -07:00
Sergio Benitez b6448fc016 Clarify 'Options::Missing' exception in 'FileServer'. 2021-08-19 19:43:34 -07:00
Gonçalo Ribeiro df8cf4575a Fix typo in 'XssFilter' API documentation: 'enorce' -> 'enforce'. 2021-07-24 14:55:49 -07:00
Joscha 85c0759f1d Fix typos in 'DataField' API documentation. 2021-07-24 14:55:45 -07:00
Sergio Benitez 534f43c223 Point to 'mtls::Certificate' in mTLS config docs. 2021-07-20 14:56:30 -07:00
Sergio Benitez cc0621626b Prefix 'content' responder names with 'Raw'.
The primary aim of this commit is to reduce confusion between
'content::Json' and 'rocket::serde::json::Json' be renaming the former
to 'content::RawJson'. The complete changes in this PR are:

  * All responders in the 'content' module are prefixed with 'Raw'.
  * The 'content::Custom' responder was removed entirely.
  * The 'Plain' responder is now 'RawText'.
  * The 'content' API docs point to the 'serde' responders.
  * The docs and examples were updated accordingly.
2021-07-20 02:09:11 -07:00
Sergio Benitez 7ffe3a7360 Complete mTLS implementation.
Resolves #254.
2021-07-09 00:05:44 -07:00
Sergio Benitez bbc36ba27f Initial implementation of mTLS.
Co-authored-by: Howard Su <howard0su@gmail.com>
Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
2021-07-09 00:05:20 -07:00
Sergio Benitez 581b63da7e Restore 'doc(cfg)' labels for config items. 2021-07-05 14:02:19 -07:00
Sergio Benitez 614f8ab46c Condition TLS config types on 'tls' feature.
Previously, TLS, via 'Config::tls', was configurable even if the 'tls'
feature was disabled. This commit changes this so that the 'Config::tls'
field and TLS config structures are only available if 'tls' is enabled.
2021-07-05 13:46:37 -07:00
Sergio Benitez 76fab37e29 Rename 'remote_addr' to 'peer_address'. 2021-07-04 15:37:27 -07:00
Sergio Benitez b5e3569554 Split TLS module into logical submodules. 2021-07-04 15:25:49 -07:00
Sergio Benitez de4b3e3891 Make 'tls' its own module. 2021-07-04 15:01:55 -07:00
Sergio Benitez 6aecff39bc Warn on launch if a custom runtime is detected.
The warning is only emitted in debug profiles.
2021-07-02 11:35:59 -07:00
Sergio Benitez 8058798a4c Properly propagate profile to 'Config' on ignite. 2021-07-02 11:34:35 -07:00
Sergio Benitez 0ffcfae47b Warn on more deprecated config keys and profiles. 2021-07-02 11:31:50 -07:00
Sergio Benitez 8414d787d9 Impl 'FromUriParam' for 'Json'. 2021-07-02 10:36:57 -07:00
Sergio Benitez 2cee4b4594 Make '&Host' a request guard. 2021-07-02 06:57:43 -07:00
Sergio Benitez c58b43700c Add type-safe 'Host' type, 'Request::host()'.
Closes #1699.
2021-07-02 06:48:40 -07:00
Sergio Benitez f49ee7da00 Make 'FileName' danger more pronounced. 2021-07-02 06:48:09 -07:00
Mikail Bagishov be933ce398 Apply clippy suggestions. 2021-06-30 14:13:19 -07:00
ThouCheese 5ebefa97c9 Impl 'std::Error' for 'serde::json::Error'. 2021-06-30 11:22:31 -07:00
Joakim Soderlund 7b9363f981 Fix typo in 'Sentinel' docs: 'INner' -> 'Inner'. 2021-06-30 11:08:20 -07:00
John-John Tedro 0ddad7a6c1 Impl 'Responder' for 'Arc<T>', 'Box<T>'. 2021-06-30 10:44:30 -07:00
PROgrm_JARvis 4339c2af48 Make '<String as FromParam>::Error' 'Infallible'.
Fixes #1679.
2021-06-30 10:27:46 -07:00
Sergio Benitez 6a3d1ac1d5 Fix 'UriDisplay<Query>' 'Json', 'MsgPack', impls.
As 'FromForm' doesn't provide access to the raw, undecoded string,
'MsgPack' cannot implement 'FromForm::from_value()'. This means that it
is not presently possible to parse a MessagePack form from a query
string. As such, the 'UriDisplay<Query>' implementation was removed.

The 'UriDisplay<Query>' for JSON was fixed such that a round-trip of a
'Json<T>' as a form works as expected.
2021-06-30 06:46:03 -07:00
Sergio Benitez bad762b8c4 Add 'rocket::serde:json::to_string()' functions. 2021-06-30 06:46:03 -07:00
Sergio Benitez 3ec58c3ca2 Ensure launch occurs with minimal ciphersuites.
Co-authored-by: Abdullah Alyan <AbdullahAlyan@yahoo.com>
2021-06-29 11:27:54 -07:00
Sergio Benitez f818702f9b Propagate TLS ciphersuite config to rustls.
Closes #1563.
2021-06-29 11:17:59 -07:00
Sergio Benitez dd722cdcfc Add configurable TLS ciphersuite preferences. 2021-06-29 10:35:55 -07:00
Sergio Benitez 5a2535f865 Mark 'form::ErrorKind' 'non_exhaustive'. 2021-06-29 05:06:37 -07:00
Sergio Benitez 9ce2935fe1 Impl 'Len' field validator for 'Json', 'MsgPack'. 2021-06-29 03:37:52 -07:00
Sergio Benitez 9399841b0c Fix order of indices in 'FromForm' map notes. 2021-06-29 03:37:52 -07:00
Sergio Benitez 793f421712 Support type generics, unit structs in 'FromForm'.
The 'FromFrom' derive now allows type generics in all positions using
the same automatic discovery technique as with 'Responder'. (In fact,
the technique was created for this derive.) Furthermore, 'FromForm' can
now be derived for unit structs.

Also adds a new 'try_with' form field validator.

Resolves #1695.
2021-06-29 03:37:52 -07:00
Sergio Benitez 2727d7bb7b Automatically discover 'Responder' generic bounds.
This commit presents and applies a new technique for bounding type
generics in derives. In short, for a generic `T` used in a field type of
`Field<T>`, where an eventual bound of `Responder` required, the derive
generates a bound of `Field<T>: Responder`. This removes the need for
any manually provided bounds while simultaneously allowing more
structures to typecheck. For example, generics in header components are
now fully supported.
2021-06-29 03:31:31 -07:00
Sergio Benitez ae796b41ad Impl std traits, 'UriDisplay<Query>' on 'MsgPack'.
This brings the 'MsgPack' impls to parity with 'Json'.
2021-06-29 03:31:31 -07:00
Sergio Benitez f827367df0 Expose 'serde::msgpack::to_vec()' methods. 2021-06-29 03:31:31 -07:00
Sergio Benitez fb3ae9f7db Impl std traits, 'UriDisplay<Query>' for 'Json'.
The 'Json' type now implements:

  * Clone
  * PartialEq
  * Eq
  * PartialOrd
  * Ord
  * Hash
  * UriDisplay<Query>

Method calls that resolve to a method in the set of traits above
previously resolved to the `Deref` target. For example, `foo.clone()`,
where `foo: Json<T>`, previously resolved to `<T as Clone>::clone()` but
now resolves to `<Json<T> as Clone>::clone()`.
2021-06-29 03:31:27 -07:00
Sergio Benitez 0e98177973 Reexport 'serde::json::to_value()'. 2021-06-29 03:10:13 -07:00
Sergio Benitez 00e56c9822 Use higher contrast emojis for routes, catchers. 2021-06-26 17:11:56 -07:00
Sergio Benitez 7f34aacd60 Add 'Missing', 'IndexFile' 'FileServer' options.
'Missing' allows constructing a 'FileServer' even if the supplied path
does not exist. 'IndexFile' allows serving a single file as the index of
the mount path.
2021-06-26 17:11:56 -07:00
Sergio Benitez d18103358e Allow 'len()' form field validations on 'Capped'.
This also adds more doctests for the 'with' validator.
2021-06-26 17:11:56 -07:00
Sergio Benitez a249f26164 Fix link to 'FromForm' derive in 'FromForm' docs. 2021-06-26 17:11:56 -07:00
Sergio Benitez 686a0ed964 Fix wording in 'config' docs. 2021-06-26 17:11:53 -07:00
Sergio Benitez b00c89c22f Support lifetime bounds in typed stream macros.
The syntax 'TypedStream![T + '_]' expands to:

  impl TypedStream<Item = T> + '_

This allows seamlessly borrowing in typed streams.

Also adds 'Event::empty()', for convenience.
2021-06-26 16:37:21 -07:00
Sergio Benitez 770f332832 Improve 'Responder' API docs.
The improvements are:

  * Point directly and immediately to the 'Responder' derive.
  * Provide more discussion on lifetimes.
  * Format documentation for easier scanning.
2021-06-26 12:41:42 -07:00
Sergio Benitez d34195fe11 Warn, don't error, if remote hangs up. 2021-06-26 12:05:04 -07:00
Sergio Benitez ef303d44f8 Fix 'TempFile' data guard warning formatting. 2021-06-26 12:03:52 -07:00
Sergio Benitez 76ec847a58 Use 'RelativePathBuf' as 'Config.temp_dir' type.
This makes a relative 'temp_dir' declared in a config file relative to
the config file itself.
2021-06-25 11:42:49 -07:00
Sergio Benitez c3ee34e295 Drop sender to prevent async client read deadlock.
Fixes #1729.

Co-authored-by: Wesley Norris <repnop@outlook.com>
2021-06-25 09:27:36 -07:00
Sergio Benitez a875da1666 Always disable colors if requested or unavailable.
Resolves #1712.
2021-06-25 09:08:49 -07:00
timando c3dc7183f3 Fix Responder documentation: remove an outdated reference to 'Future'. 2021-06-17 17:20:04 -07:00
timando af1aa079d6 Fix a word in the 'Data::peek' docs: 'max' -> 'min'. 2021-06-14 19:36:03 -07:00
Sergio Benitez d2c2725689 Implement 'De(Serialize)' for 'Method'. 2021-06-09 17:07:26 -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 1aa551ada6 Ignore heartbeats in non-heartbeat SSE test. 2021-06-09 04:51:46 -07:00
Sergio Benitez 01436d2d24 Fix a ton of broken links. 2021-06-09 04:51:46 -07:00
Sergio Benitez b19544c346 Fix doc typo: "Contracting" -> "Constructing". 2021-06-08 23:13:03 -07:00
Sergio Benitez 128234d9a8 Allow customizing and removing 'Server' header. 2021-06-08 23:09:57 -07:00
Sergio Benitez 6206a46222 Try to preserve header casing in HTTP/1.1.
Unfortunately, this doesn't actually do anything at the moment due to
what appears to be a bug in hyper.
2021-06-08 23:00:59 -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 7595450adc Use published 'state'. 2021-06-07 20:34:27 -07:00
Sergio Benitez 333da45470 Allow non-breaking config additions.
If stars aligned properly, we might imagine writing this:

    #[non_exhaustive]
    struct Config {
        pub field: Foo,
        pub other: Bar,
    }

...with semantics that would allow the defining crate (here, Rocket), to
construct the structure directly while consumers would need to use
public constructors or struct update syntax:

    Config {
        field: Foo,
        other: Bar,
        ..Default::default()
    }

Alas, this is not the way `non_exhaustive` works on structs. You cannot
use field-update syntax to construct `Config` above. You must use public
constructors. This means builder methods or mutating an already built
struct. This is not what we want.

I don't know why it works this way. I don't see why it must. Something
something Drop.

So we have this hack from the pre-non_exhaustive era.
2021-06-07 19:31:23 -07:00
Sergio Benitez 5f50d5e232 Check for trailing new lines in testing script. 2021-06-07 19:31:23 -07:00
Sergio Benitez 0aa9a11ca4 Fix typos throughout codebase. 2021-06-07 19:31:21 -07:00
Sergio Benitez 94a5f5eca6 Fuzz URI parsing and display. 2021-06-06 21:52:44 -07:00
Sergio Benitez 0d53e23bf6 Discover sentinels in known type macros.
Resolves #1657.
2021-06-03 19:31:30 -07:00
Sergio Benitez dc5c57b624 Be even more tolerant in heartbeat testing. 2021-06-03 02:51:06 -07:00
Sergio Benitez 1e4db983e8 Fix, finish 'FromForm' derive field defaults.
Resolves #1536.
2021-06-03 00:05:02 -07:00
ThouCheese ebb9f3cfdd Allow field defaults in 'FromForm' derive. 2021-06-03 00:02:32 -07:00
Sergio Benitez 559320d155 Increase tolerance in SSE heartbeat test. 2021-06-02 22:35:50 -07:00
toshokan 27519a97ea Fix typo in 'Request' docs: no`n`th -> `n`th. 2021-06-02 17:43:15 -07:00
Sergio Benitez 0cd8bd2313 Initialize logger earlier to log more errors.
Specifically, errors that occurred _before_ ignite time went unlogged as
no logger was initialized. This commit rectifies the situation.
2021-06-02 17:25:07 -07:00
Sergio Benitez f8efa64ae2 Expose 'msgpack::from_slice', 'json::from_value'. 2021-06-02 16:59:42 -07:00
Sergio Benitez a8f6103b99 Introduce Server-Sent Event Streams.
Resolves #33.
2021-06-01 13:47:50 -07:00
Sergio Benitez 8029ea319f Expose 'serde::json::{from_str,from_slice}'. 2021-06-01 13:47:50 -07:00
Jeb Rosen 2076b693b1 Add initial Server-Sent Events implementation. 2021-06-01 13:19:58 -07:00
Sergio Benitez bcd62e5373 Add 'Join' stream combinator extension. 2021-06-01 11:46:17 -07:00
Sergio Benitez ed3cc13b84 Add internal '__typed_stream' proc-macro.
This resolves syntax ambiguity issues with public typed-stream macros.
Prior to this commit, greedy single-token matching by macro-rules macros
would result in certain tokens at the beginning of the macro input, such
as 'for', inadvertently triggering a '$ty' matching case resulting in
incorrect expansion.
2021-06-01 11:43:51 -07:00
Sergio Benitez 009be32a8c Improve request conversion performance, semantics.
This commit makes the following improvements to core request handling:

  * Absolute target URIs are not rejected. Instead, the path and query
    parts are passed through the application. This resolves an issue
    where certain HTTP/2 requests would be rejected by Rocket.
  * Data is never copied from the request. Previously, Rocket would copy
    and allocate for incoming headers.
  * Non-UTF-8 headers are dropped with a warning instead of being
    lossily, and thus perhaps incorrectly, decoded as UTF-8. The final
    fix is to properly support non-UTF-8 headers, no matter how in the
    minority they are.

Resolves #1498.
2021-06-01 11:36:57 -07:00
Sergio Benitez df286668b5 Add arbitrary function 'with' field validator. 2021-06-01 11:33:40 -07:00
Sergio Benitez 8214df4a56 Allow more types in 'contains' field validator.
The validator can now validate string contents with:

    * '&[char]'
    * 'F: FnMut(char) -> bool'
2021-06-01 11:30:34 -07:00
Sergio Benitez cf5ccc4b2e Fix MIME confusion attack URL in 'NoSniff' policy. 2021-06-01 11:27:43 -07:00
Sergio Benitez 1bf8862796 Move stream responders into their own module.
This is largely an internal change. However, this commit also renamed
the 'Once' stream to the more apt 'One', a visible breaking change.
2021-06-01 11:16:40 -07:00
Sergio Benitez 3a3d0ce518 Protect graceful shutdown against runaway I/O. 2021-05-31 23:47:52 -07:00
Sergio Benitez 6b4c1b71d7 Update 'tokio' to 1.6.1. 2021-05-29 15:33:15 -07:00
Sergio Benitez 1f1976f8bf Avoid Tokio 1.6 due to tokio-rs/tokio#3803. 2021-05-27 15:25:57 -07:00
Sergio Benitez 41d7138540 Allow custom generic bounds in 'Responder' derive. 2021-05-26 02:26:11 -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
Sergio Benitez faaa9c9065 Fixup URI (de)serialization. 2021-05-24 12:16:03 -07:00
Matthew Pomes 1233518733 Implement (De)Serialize for all URI variants.
Closes #1593.
2021-05-24 12:15:52 -07:00
Sergio Benitez bf9de1d39e Fix typo: 'Rocket.toml' -> 'Cargo.toml'. 2021-05-23 18:20:55 -07:00
Sergio Benitez 9e9c708a16 Expose 'Context::{push_error,push_errors}'.
Closes #1582.

Co-authored-by: Francois Stephany <francois@tamere.eu>
2021-05-23 18:18:24 -07:00
Sergio Benitez 8a9000a9cb Document the 'Contextual' form guard. 2021-05-23 18:09:43 -07:00
Sergio Benitez ab13d73b30 Prefer using 'io::Result' responder in docs. 2021-05-22 22:12:46 -07:00
Sergio Benitez da996cddc3 Use upstream 'async-stream'. 2021-05-22 22:00:18 -07:00
Sergio Benitez 2d70027a1b Avoid file system races in 'TempFile' doctests.
This changes 'TempFile' doctests so that different file names are used
across them, avoiding race conditions where one test deletes a file
another test just created and thus expects to subsequently exist.
2021-05-22 21:00:09 -07:00
Sergio Benitez 59851a621c Add 'Outcome::{ok_map_forward,ok_map_failure}'.
Closes #1622.
2021-05-22 20:37:42 -07:00
Sergio Benitez 2f94c4fbdc Improve 'Outcome' docs, method order, tracking. 2021-05-22 20:37:18 -07:00
Sergio Benitez a13a2f4a84 Move 'FileName', 'TempFile', 'NamedFile' to 'fs'.
This consolidates all file system related types into one module.
2021-05-22 16:22:01 -07:00
Sergio Benitez b1d05d20ac Graduate 'serve' into core as 'fs', 'FileServer'.
This completes the graduation of stable 'contrib' features to 'core'.

Closes #1107.
2021-05-22 11:15:56 -07:00
Sergio Benitez a78814f1c5 Graduate contrib 'uuid' into core.
This has the following nice benefits:

  * The 'Uuid' wrapper type is gone.
  * 'Uuid' implements 'UriDisplay', 'FromUriParam'.
  * The 'serialization' example merges in 'uuid'.

Resolves #1299.
2021-05-22 11:01:00 -07:00
Sergio Benitez f6a7087c84 Graduate 'helmet' as 'shield' into core.
The 'SpaceHelmet' fairing is now called 'Shield'. It features the
following changes and improvements:

  * Headers which are now ignored by browsers are removed.
  * 'XssFilter' is no longer an on-by-default policy.
  * A new 'Permission' policy is introduced.
  * 'Shield' is attached to all 'Rocket' instances by default.
  * Default headers never allocate on 'Clone'.
  * Policy headers are rendered once and cached at start-up.
  * Improved use of typed URIs in policy types.
2021-05-22 11:01:00 -07:00
Sergio Benitez 267cb9396f Introduce 'Singleton' fairings.
A singleton fairing is guaranteed to be the only instance of its type at
launch time. If more than one instance of a singleton fairing is
attached, only the last instance is retained.
2021-05-22 11:01:00 -07:00
Sergio Benitez 824edef3fc Prevent double-panic on 'Error' drop.
Previously, if a panic occurred with an 'Error' on the stack, 'Error'
would panic as usual during unwinding. This resulted in a double panic.
This commit makes 'Error' detect if a panic is already occurring and
omits its own panic if it is.
2021-05-22 11:01:00 -07:00
Sergio Benitez c74bcfd40a Graduate contrib 'json' and 'msgpack' into core.
This has the following nice benefits:

  * The 'JsonValue' wrapper type is gone.
  * 'Local{Request, Response}' natively support JSON/MessagePack.
  * The 'json' and 'msgpack' limits are officially recognized.
  * Soon, Rocket application will not require an explicit 'serde' dep.

This marks the beginning of the end of 'rocket_contrib'.
2021-05-22 11:01:00 -07:00
Sergio Benitez fa3e0334c1 Overhaul URI types, parsers, 'uri!' macro.
This commit entirely rewrites Rocket's URI parsing routines and
overhauls the 'uri!' macro resolving all known issues and removing any
potential limitations for compile-time URI creation. This commit:

  * Introduces a new 'Reference' URI variant for URI-references.
  * Modifies 'Redirect' to accept 'TryFrom<Reference>'.
  * Introduces a new 'Asterisk' URI variant for parity.
  * Allows creation of any URI type from a string literal via 'uri!'.
  * Enables dynamic/static prefixing/suffixing of route URIs in 'uri!'.
  * Unifies 'Segments' and 'QuerySegments' into one generic 'Segments'.
  * Consolidates URI formatting types/traits into a 'uri::fmt' module.
  * Makes APIs more symmetric across URI types.

It also includes the following less-relevant changes:

  * Implements 'FromParam' for a single-segment 'PathBuf'.
  * Adds 'FileName::is_safe()'.
  * No longer reparses upstream request URIs.

Resolves #842.
Resolves #853.
Resolves #998.
2021-05-19 18:47:11 -07:00
Sergio Benitez 8e4ddc06f2 Use upstream 'multer' 2.0. 2021-05-18 21:46:51 -07:00
Sergio Benitez d03a07b183 Retrieve managed state via a borrow: '&State<T>'.
This has the following positive effects:

  1) The lifetime retrieved through 'Deref' is now long-lived.
  2) An '&State<T>` can be created via an '&T'.
  3) '&State<T>' is shorter to type than 'State<'_, T>'.
2021-05-11 08:58:16 -05:00
Sergio Benitez 3a7559edce Introduce 'mercy' connection shutdown period.
This improves graceful shutdown by allowing connection-level I/O to
shutdown gracefully within a 'mercy' period.
2021-04-29 19:19:07 -07:00
Sergio Benitez fe23eaebd1 Document 'async' attributes. 2021-04-28 21:58:14 -07:00
Sergio Benitez ad8d80907b Remove unused reason phrase in 'Status'.
Closes #534.

Co-authored-by: YetAnotherMinion <yam@thinkalexandria.com>
2021-04-28 21:26:41 -07:00
Sergio Benitez 336a03e27f Introduce async streams.
This reworks the entire 'response::stream' module for async streams.

Resolves #1066.
2021-04-28 04:01:02 -07:00
Sergio Benitez a72e8da735 Implement graceful shutdown.
The crux of the implementation is as follows:

  * Configurable ctrl-c, signals that trigger a graceful shutdown.
  * Configurable grace period before forced I/O termination.
  * Programatic triggering via an application-wide method.
  * A future (`Shutdown`) that resolves only when shutdown is requested.

Resolves #180.
2021-04-28 03:20:44 -07:00
Sergio Benitez 63e6845386 Revamp 'Response', 'Body' types.
This is a breaking change for many consumers of the 'Response' and all
consumers of the 'Body' API. The summary of breaking changes is:

  * 'Response::body()', 'Response::body_mut()' are infallible.
  * A 'Body' can represent an empty body in more cases.
  * 'ResponseBuilder' is now simply 'Builder'.
  * Direct body read methods on 'Response' were removed in favor of
    chaining through 'body_mut()': 'r.body_mut().to_string()'.
  * Notion of a 'chunked_body' was removed as it was inaccurate.
  * Maximum chunk size can be set on any body.
  * 'Response' no longer implements 'Responder'.

A few bugs were fixed in the process. Specifically, 'Body' will emit an
accurate size even for bodies that are partially read, and the size of
seek-determined bodies is emitted on HEAD request where it wasn't
before. Specifics on transport were clarified, and 'Body' docs greatly
improved as a result.
2021-04-28 02:21:33 -07:00
Sergio Benitez e7b28f18a9 Doc 'form' items, 'async_test', private macros. 2021-04-28 02:21:30 -07:00
Sergio Benitez fd36a6d7fe Rename 'verbose_' form validators to 'dbg_'. 2021-04-28 01:58:45 -07:00
Sergio Benitez bab3b1cb5b Mod-export 'msg!', 'local_cache!', 'try_outcome!'.
This removes the export of each of these macros from the root, limiting
their export-scope to their respective module. This is accomplished
using a new internal macro, 'export!', which does some "magic" to work
around rustdoc deficiencies.
2021-04-28 01:58:42 -07:00
Sergio Benitez d21608ca7b Remove 'Content' in favor of 'content::Custom'.
Also adds the shorthand '(ContentType, R)', where 'R: Responder',
responder implementation. This brings it to parity with the
'response::status' API.
2021-04-28 01:21:57 -07:00
Sergio Benitez 03d759ab90 Make type macros inelgible as sentinels. 2021-04-28 01:18:20 -07:00
Sergio Benitez 068aacd79d Require source lines to be under 100 chars. 2021-04-27 20:19:35 -07:00
Sergio Benitez 801e04bd53 Log guard failures, potential misuses.
This commit includes changes that improve how and what Rocket logs
automatically. Rocket now logs:

  * All guard errors, indicating the failing guard kind and type.
  * A warning when a 'TempFile' is used as a data guard for a request
    that specifies a 'form' Content-Type.
  * Only the top/sub of a request's format.

This commit makes the following breaking changes:

  * '<T as FromData>::Error' must implement 'Debug'.

Furthermore, this commit restores the previous behavior of always
logging launch info. It further restores the unspecified behavior of
modifying logging state only when the set logger is Rocket's logger.
2021-04-23 19:19:39 -07:00
Sergio Benitez 08c0701bdc Clarify internal sentinel docs. 2021-04-23 19:19:39 -07:00
Sergio Benitez 64e46b7107 Introduce sentinels: auto-discovered launch abort.
Sentinels resolve a long-standing usability and functional correctness
issue in Rocket: starting an application with guards and/or responders
that depend on state that isn't available. The canonical example is the
'State' guard. Prior to this commit, an application with routes that
queried unmanaged state via 'State' would fail at runtime. With this
commit, the application refuses to launch with a detailed error message.

The 'Sentinel' docs explains it as:

    A sentinel, automatically run on ignition, can trigger a launch
    abort should an instance fail to meet arbitrary conditions. Every
    type that appears in a mounted route's type signature is eligible to
    be a sentinel. Of these, those that implement 'Sentinel' have their
    'abort()' method invoked automatically, immediately after ignition,
    once for each unique type. Sentinels inspect the finalized instance
    of 'Rocket' and can trigger a launch abort by returning 'true'.

The following types are now sentinels:

  * 'contrib::databases::Connection' (any '#[database]' type)
  * 'contrib::templates::Metadata'
  * 'contrib::templates::Template'
  * 'core::State'

The following are "specialized" sentinels, which allow sentinel
discovery even through type aliases:

  * 'Option<T>', 'Debug<T>' if 'T: Sentinel'
  * 'Result<T, E>', 'Either<T, E>' if 'T: Sentinel', 'E: Sentinel'

Closes #464.
2021-04-16 01:44:53 -07:00
Sergio Benitez fe4d0425e6 Remove unnecessary second 'Handler' lifetimes. 2021-04-14 22:17:21 -07:00
Sergio Benitez 4f3511786c Introduce statically-enforced 'Rocket' phasing.
The core 'Rocket' type is parameterized: 'Rocket<P: Phase>', where
'Phase' is a newly introduced, sealed marker trait. The trait is
implemented by three new marker types representing the three launch
phases: 'Build', 'Ignite', and 'Orbit'. Progression through these three
phases, in order, is enforced, as are the invariants guaranteed by each
phase. In particular, an instance of 'Rocket' is guaranteed to be in its
final configuration after the 'Build' phase and represent a running
local or public server in the 'Orbit' phase. The 'Ignite' phase serves
as an intermediate, enabling inspection of a finalized but stationary
instance. Transition between phases validates the invariants required
by the transition.

All APIs have been adjusted appropriately, requiring either an instance
of 'Rocket' in a particular phase ('Rocket<Build>', 'Rocket<Ignite>', or
'Rocket<Orbit>') or operating generically on a 'Rocket<P>'.
Documentation is also updated and substantially improved to mention
required and guaranteed invariants.

Additionally, this commit makes the following relevant changes:

  * 'Rocket::ignite()' is now a public interface.
  * 'Rocket::{build,custom}' methods can no longer panic.
  * 'Launch' fairings are now 'ignite' fairings.
  * 'Liftoff' fairings are always run, even in local mode.
  * All 'ignite' fairings run concurrently at ignition.
  * Launch logging occurs on launch, not any point prior.
  * Launch log messages have improved formatting.
  * A new launch error kind, 'Config', was added.
  * A 'fairing::Result' type alias was introduced.
  * 'Shutdown::shutdown()' is now 'Shutdown::notify()'.

Some internal changes were also introduced:

  * Fairing 'Info' name for 'Templates' is now 'Templating'.
  * Shutdown is implemented using 'tokio::sync::Notify'.
  * 'Client::debug()' is used nearly universally in tests.

Resolves #1154.
Resolves #1136.
2021-04-13 19:26:45 -07:00
Sergio Benitez 887b2aed87 Move catcher, route types into eponymous modules.
In the course, significantly improve their documentation.
2021-04-13 18:58:05 -07:00
Sergio Benitez 33cff5938c Export 'const's for 'Config' parameter names. 2021-04-13 18:15:35 -07:00
Sergio Benitez fd8c9ce795 Use launch-inferred '_' in most example code. 2021-04-13 18:12:39 -07:00
Sergio Benitez d7d7bb91ec Implement a more performant 'ReaderStream'. 2021-04-13 17:45:09 -07:00
Sergio Benitez f8047f3d34 Improve 'local_cache!' example. 2021-04-13 17:41:10 -07:00
Sergio Benitez c16105dc58 Impl 'DerefMut', 'inner_mut()' for 'LocalRequest'. 2021-04-13 17:40:22 -07:00
Sergio Benitez ad36b769bc Rename 'rocket::ignite()' to 'rocket::build()'.
...because loading up a Rocket while it's ignited is a bad idea.

More seriously, because 'Rocket.ignite()' will become an "execute
everything up to here" method.
2021-04-08 01:07:52 -07:00
Sergio Benitez 50c9e88cf9 Completely revamp, redo examples.
The new examples directory...

  * Contains a `README.md` explaining each example.
  * Consolidates examples into more complete chunks.
  * Is just better.

Resolves #1447.
2021-04-07 23:09:05 -07:00
Sergio Benitez cfd5af38fe Set better default 'diesel::SQLite' options.
The options set WAL, a 1s busy timeout, and enables foreign keys.

This also adds a focused 'databases::Config::figment()', used to
retrieve a focused figment for a given config.
2021-04-07 23:09:05 -07:00
Sergio Benitez 5931d6704b Split 'AdHoc::on_launch' into two by fallibility.
The new 'AdHoc::try_on_launch()' replaces the previous 'on_launch'. The
new 'on_launch' returns a 'Rocket' directly.
2021-04-07 23:09:05 -07:00
Sergio Benitez 3535d08ff8 Impl 'FromFormField' for 'Cow', 'Capped<Cow>'. 2021-04-07 23:09:05 -07:00
Sergio Benitez e157904524 Parse empty bool values as 'true'.
This allows a field 'f: bool' to parse as true for the query '?f'.
2021-04-07 23:09:05 -07:00
Sergio Benitez b29b7bf413 Clarify non-specificity driven collisions. 2021-04-07 23:09:05 -07:00
Sergio Benitez 49b65c3ccc Filter out 'r2d2' log messages in non-debug. 2021-04-07 23:09:05 -07:00
Sergio Benitez 8d28e845d9 Rename 'Flash' 'name', 'msg' to 'kind', 'message'.
This is now consistent with the serialization of 'Flash' and better
illustrates the purpose of the late 'name' property.

Additionally, take 'Into<String>' instead of 'AsRef<str>' so we only
allocate when necessary.
2021-04-07 23:09:05 -07:00
Sergio Benitez 764ea06e90 Preserve non-'Config' values in 'Client::debug()'. 2021-04-07 23:09:05 -07:00
Sergio Benitez 8a2592c257 Use multithreaded runtime in blocking client.
The runtime uses a single worker thread. Using a multithreaded runtime
allows futures that require a multithreaded runtime to run.
2021-04-07 23:09:05 -07:00
Sergio Benitez 6ad14dc3f6 Takes URIs as 'TryInto<Origin>' in local client.
In particular, this allows passing in type-safe URIs constructed via the
'uri!' macro, which was not possible before.
2021-04-07 23:09:05 -07:00