Commit Graph

572 Commits

Author SHA1 Message Date
Sergio Benitez 723afa317a Remove 'Copy' impl on 'Segments' iterator.
This ideally prevents logic bugs where one thinks they've modified the
iterator where, in reality, a new iterator has been returned.
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 cad5494d42 Document ignored segments. 2021-06-07 17:22:35 -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 78352c787d Add 'ContentType::EventStream' known media type.
The value maps to "text/event-stream".
2021-06-01 11:46:47 -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 86c8000036 Improve 'self' token spans in field validators. 2021-06-01 11:34:31 -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 e73ff8c614 Impl 'PartialEq<Cow<RawStr>>' for 'RawStr'. 2021-06-01 11:16:40 -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 2b8104ee2c Consistently prefix codegen variables with '__'.
Closes #1656.
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 28ba04b47b Impl 'IntoCollection' for '[T; N]'.
This introduces const generics into the codebase for a more efficient,
clone-free 'IntoCollection' for arrays.
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