Commit Graph

518 Commits

Author SHA1 Message Date
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
Jeb Rosen a0784b4b15 Catch and gracefully handle panics in routes and catchers. 2021-03-05 22:58:28 -08:00
Sergio Benitez 7784cc982a Allow multiple and uncased field renamings. 2021-03-05 18:09:12 -08:00
Sergio Benitez 5ed3c13240 Remove 'extern crate's in generated URI macro.
Resolves #1554.
2021-03-05 14:21:52 -08:00
Sergio Benitez 4d0042c395 Allow '<path..>' to match zero segments.
This changes core routing so that '<path..>' in a route URI matches zero
or more segments. Previously, '<path..>' matched _1_ or more.

  * Routes '$a' and '$b/<p..>' collide if $a and $b previously collided.
  * For example, '/' now collides with '/<p..>'.
  * Request '$a' matches route '$b/<p..>' if $a previously matched $b.
  * For example, request '/' matches route '/<p..>'.

Resolves #985.
2021-03-05 02:01:24 -08:00
Sergio Benitez 08ae0d0b8c Use upstream 'async-trait'. 2021-03-04 22:10:59 -08:00
Sergio Benitez 3bce76f5af Use 'Client::debug()' in more tests. 2021-03-04 21:53:22 -08:00
Sergio Benitez 67fef233a0 Fix 'rocket::local' docstring import spacing. 2021-03-04 21:53:22 -08:00
Sergio Benitez 58f365dac4 Always return 'Segments' from 'Request::segments()'.
The iterator may be empty. This changes the return type of
'Request::segments()' from 'Option<Segments>' to simply 'Segments'.

Internally also adds a 'Client::debug()' for easier request testing.
2021-03-04 21:53:22 -08:00
Sergio Benitez 5977fe1236 Impl 'Deref' to 'Request' for 'LocalRequest'. 2021-03-04 21:53:22 -08:00
Sergio Benitez 630f2c1105 Remove unused 'RouteUriError::Segment' variant. 2021-03-04 02:49:29 -08:00
Sergio Benitez a3946377f7 Use 'UriPart::Kind' to avoid unreachable match arms. 2021-03-04 02:48:07 -08:00
Sergio Benitez 7628546ca2 Improve 'FromForm' derive error spans. 2021-03-04 02:11:06 -08:00
Sergio Benitez 398a044eb0 Complete forms documentation. Improve 'validate'.
* Add a `msg!()` macro to easily change a field validation message.
  * Allow a field to refer to itself via `self.field`.
  * Improve the various field validation traits.
2021-03-04 02:08:40 -08:00
Sergio Benitez 78e2f8a3c9 Revamp codegen, fixing inconscpicuous bugs.
This commit completely revamps the way that codegen handles route URI
"parameters". The changes are largely internal. In summary, codegen code
is better organized, better written, and less subject to error.

There are three breaking changes:
  * `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]`
    becomes `#[route(GET, uri = "..")]`.
  * the order of execution for path and query guards relative to
    each-other is now unspecified
  * URI normalization now normalizes the query part as well.

Several error messages were improved. A couple of bugs were fixed:
  * Prior to this commit, Rocket would optimistically try to parse every
    segment of a URI as an ident, in case one was needed in the future.
    A bug in rustc results in codegen "panicking" if the segment
    couldn't _lex_ as an ident. This panic didn't manifest until far
    after expansion, unfortunately. This wasn't a problem before as we
    only allowed ident-like segments (ASCII), but now that we allow any
    UTF-8, the bug surfaced. This was fixed by never attempting to parse
    non-idents as idents.
  * Prior to this commit, it was impossible to generate typed URIs for
    paths that ignored path parameters via the recently added syntax
    `<_>`: the macro would panic. This was fixed by, well, handling
    these ignored parameters.

Some minor additions:
  * Added `RawStr::find()`, expanding its `Pattern`-based API.
  * Added an internal mechanism to dynamically determine if a `UriPart`
    is `Path` or `Query`.
2021-03-04 02:01:25 -08:00
Sergio Benitez 63a14525d8 UTF-8 routes. Forms revamp. Temp files. Capped.
So. Many. Changes.

This is an insane commit: simultaneously one of the best (because of all
the wonderful improvements!) and one of the worst (because it is just
massive) in the project's history.

Routing:
  * All UTF-8 characters are accepted everywhere in route paths. (#998)
  * `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]`
    becomes `#[route(GET, uri = "..")]`.

Forms Revamp
  * All form related types now reside in a new `form` module.
  * Multipart forms are supported. (resolves #106)
  * Collections are supported in forms and queries. (resolves #205)
  * Nested structures in forms and queries are supported. (resolves #313)
  * Form fields can be ad-hoc validated with `#[field(validate = expr)]`.
  * `FromFormValue` is now `FromFormField`, blanket implements `FromForm`.
  * Form field values are always percent-decoded apriori.

Temporary Files
  * A new `TempFile` data and form guard allows streaming data directly to a
    file which can then be persisted.
  * A new `temp_dir` config parameter specifies where to store `TempFile`.
  * The limits `file` and `file/$ext`, where `$ext` is the file extension,
    determines the data limit for a `TempFile`.

Capped
  * A new `Capped` type is used to indicate when data has been truncated due to
    incoming data limits. It allows checking whether data is complete or
    truncated.
  * `DataStream` methods return `Capped` types.
  * `DataStream` API has been revamped to account for `Capped` types.
  * Several `Capped<T>` types implement `FromData`, `FromForm`.
  * HTTP 413 (Payload Too Large) errors are now returned when data limits are
    exceeded. (resolves #972)

Hierarchical Limits
  * Data limits are now hierarchical, delimited with `/`. A limit of `a/b/c`
    falls back to `a/b` then `a`.

Core
  * `&RawStr` no longer implements `FromParam`.
  * `&str` implements `FromParam`, `FromData`, `FromForm`.
  * `FromTransformedData` was removed.
  * `FromData` gained a lifetime for use with request-local data.
  * The default error HTML is more compact.
  * `&Config` is a request guard.
  * The `DataStream` interface was entirely revamped.
  * `State` is only exported via `rocket::State`.
  * A `request::local_cache!()` macro was added for storing values in
    request-local cache without consideration for type uniqueness by using a
    locally generated anonymous type.
  * `Request::get_param()` is now `Request::param()`.
  * `Request::get_segments()` is now `Request::segments()`, takes a range.
  * `Request::get_query_value()` is now `Request::query_value()`, can parse any
    `FromForm` including sequences.
  * `std::io::Error` implements `Responder` like `Debug<std::io::Error>`.
  * `(Status, R)` where `R: Responder` implements `Responder` by overriding the
    `Status` of `R`.
  * The name of a route is printed first during route matching.
  * `FlashMessage` now only has one lifetime generic.

HTTP
  * `RawStr` implements `serde::{Serialize, Deserialize}`.
  * `RawStr` implements _many_ more methods, in particular, those related to the
    `Pattern` API.
  * `RawStr::from_str()` is now `RawStr::new()`.
  * `RawStr::url_decode()` and `RawStr::url_decode_lossy()` only allocate as
    necessary, return `Cow`.
  * `Status` implements `Default` with `Status::Ok`.
  * `Status` implements `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`.
  * Authority and origin part of `Absolute` can be modified with new
    `Absolute::{with,set}_authority()`, `Absolute::{with,set}_origin()` methods.
  * `Origin::segments()` was removed in favor of methods split into query and
    path parts and into raw and decoded versions.
  * The `Segments` iterator is smarter, returns decoded `&str` items.
  * `Segments::into_path_buf()` is now `Segments::to_path_buf()`.
  * A new `QuerySegments` is the analogous query segment iterator.
  * Once set, `expires` on private cookies is not overwritten. (resolves #1506)
  * `Origin::path()` and `Origin::query()` return `&RawStr`, not `&str`.

Codegen
  * Preserve more spans in `uri!` macro.
  * Preserve spans `FromForm` field types.
  * All dynamic parameters in a query string must typecheck as `FromForm`.
  * `FromFormValue` derive removed; `FromFormField` added.
  * The `form` `FromForm` and `FromFormField` field attribute is now named
    `field`. `#[form(field = ..)]` is now `#[field(name = ..)]`.

Contrib
  * `Json` implements `FromForm`.
  * `MsgPack` implements `FromForm`.
  * The `json!` macro is exported as `rocket_contrib::json::json!`.
  * Added clarifying docs to `StaticFiles`.

Examples
  * `form_validation` and `form_kitchen_sink` removed in favor of `forms`.
  * The `hello_world` example uses unicode in paths.
  * The `json` example only allocates as necessary.

Internal
  * Codegen uses new `exports` module with the following conventions:
    - Locals starts with `__` and are lowercased.
    - Rocket modules start with `_` and are lowercased.
    - `std` types start with `_` and are titlecased.
    - Rocket types are titlecased.
  * A `header` module was added to `http`, contains header types.
  * `SAFETY` is used as doc-string keyword for `unsafe` related comments.
  * The `Uri` parser no longer recognizes Rocket route URIs.
2021-03-04 01:51:21 -08:00
Jeb Rosen 9d45e786bb Update 'rand' dependency to 0.8. 2021-02-28 16:34:38 -08:00
Rudi Floren e332ee83da Add missing lifetime parameter in codegen for routes and catchers.
This is linted against by `elided_lifetimes_in_paths`, which is not
enabled by default but is part of the `rust_2018_idioms` lint group.
2021-02-28 15:59:45 -08:00
Jeb Rosen 87f03d3b26 Update UI tests for latest nightly and 'pear' error messages. 2021-02-26 22:15:37 -08:00
ami-GS 38e4067a58 Fix invalid JSON syntax in doc examples: remove trailing commas. 2021-02-20 12:01:44 -08:00
Jeb Rosen 453fa037da Update UI tests for latest stable. 2021-02-20 12:01:44 -08:00
Sergio Benitez aaea84d750 Check profile in jail to avoid env races. 2021-02-19 12:49:39 -08:00
Sergio Benitez 2a49368313 Update UI tests for latest nightly. 2021-02-09 17:17:44 -08:00
Sergio Benitez 0af25bfb6d Move derive attribute after derive. 2021-02-09 17:17:26 -08:00
Sergio Benitez e325e2fce4 Fix soundness issue: make 'Formatter' panic-safe.
Fixes #1534.
2021-02-09 16:58:34 -08:00
Sergio Benitez c24f15c18f Add regression test for #1503.
Closes #1503.
2021-01-14 15:15:57 -08:00
Sergio Benitez 407e346a6a Clean up 'on_launch_fairing_can_inspect_port' test. 2021-01-13 17:20:44 -08:00
Filip Gospodinov 48fd83a31d Run launch fairings after effective port is known. 2021-01-13 17:20:33 -08:00
Sergio Benitez 43ade920c5 Warn when deprecated profiles are set. 2021-01-13 16:21:36 -08:00
Sergio Benitez 28976a5bd3 Preserve 'secret_key' in 'Config' provider data.
Also fixes emission of 'secret_key' warnings when 'secrets' feature is
disabled.

Resolves #1505.
Fixes #1510.
2021-01-13 16:01:39 -08:00
Jeb Rosen 92af8fca72 Update to 'tokio' 1.0, 'hyper' 0.14. 2021-01-13 15:22:16 -08:00
Sergio Benitez 031948c1da Remove superfluous semicolons. 2021-01-13 14:30:08 -08:00
Brendon Federko cb33429ce4 Enable 'std' 'indexmap' feature. 2021-01-12 14:52:37 -08:00
Brendon Federko e68a951a54 Upodate tests for latest stable. 2021-01-12 14:52:34 -08:00
Sergio Benitez 9671115796 Use 'workers' value from 'Config::figment()'.
This commit also improves config pretty-printing and warning messages.
It also fixes an issue that resulted in config value deprecation
warnings not being emitted. The 'workers' value is now a 'usize', not a
'u16'; contrib pool sizes now default to 'workers * 2'.

Closes #1470.
2020-12-24 15:58:48 -08:00
Jeb Rosen 1f1f44f336 Update UI tests for latest stable. 2020-11-21 12:42:57 -08:00
Sergio Benitez fa77435187 Bust cache on 'Request::{add,replace}_header()'.
Also changes 'Header::name()' to return '&UncasedStr'.

Resolves #518.
2020-11-05 21:03:58 -08:00
Sergio Benitez 86ff66a69c Streamline raw identifier support in codegen. 2020-11-03 12:07:23 -08:00
Jeb Rosen 97f6bc5dc0 Support raw identifiers in forms, routes, uri.
Resolves #881.
2020-11-03 01:42:37 -08:00
Sergio Benitez b5e4dded8a Accept browser-sent unencoded query characters.
Closes #941.

Co-authored-by: Vladimir Ignatev <ya.na.pochte@gmail.com>
2020-11-02 15:08:33 -08:00
Sergio Benitez 949bb01e2d Generate path encoding set using 'const fn'.
Co-authored-by: Jakub Wieczorek <jakub.adam.wieczorek@gmail.com>
2020-11-01 21:26:31 -08:00
Sergio Benitez 337e8843a4 Use 'Option', 'Result' directly in 'uri!' query.
Prior to this commit, the conversion 'T -> Option<T>' was applied in
both the path and query parts of a URI in the 'uri' macro via the
'FromUriParam' trait with no implementation for 'Option<T>' directly.
This meant that it was impossible to directly render an 'Option<T>'.
This was exactly desired for the path part, where rendering a 'None'
would yield an incorrect URI, but the restriction was too strict for the
query part, where a 'None' is entirely valid. This commit makes changes
the conversion so that it only applied to path parts and adds the
identity conversions for 'Option<T>' and 'Result<T, E>' for query parts.

The side effect is a breaking change: due to conflicting impls, the 'T'
to 'Option<T>' conversion was removed for query parts. Thus, all 'uri!'
query route arguments of type 'Option' or 'Result' must now be wrapped
in 'Some' or 'Ok'. Due to new 'Option<T> <-> Result<T, E>' conversions,
either 'Some' _and_ 'Ok' work in both contexts.

Closes #1420.
2020-11-01 10:30:30 -08:00
Sergio Benitez edc91f65b7 Mimic Rocket's config in custom providers example. 2020-10-30 03:08:26 -07:00
Sergio Benitez 55b651bd70 Use 'rocket::custom()' for 'State' tests. 2020-10-30 02:49:00 -07:00
Jonty b7565172eb Impl 'Clone' for 'State'.
Resolves #1411.
2020-10-30 02:16:24 -07:00
Sergio Benitez a6f5a63535 Add tests for ignored parameters '<_>'.
Co-authored-by: timokoesters <timo@koesters.xyz>
2020-10-30 00:47:41 -07:00
Sergio Benitez 8e8fb4cae8 Allow ignored route path segments.
Co-authored-by: timokoesters <timo@koesters.xyz>
2020-10-30 00:06:39 -07:00
Sergio Benitez 23738446f0 Impl 'std::error::Error' for 'Error'.
Resolves #1460.
2020-10-27 16:04:25 -07:00
Sergio Benitez 8570afff3e Use threaded scheduler in tests.
This prevents async I/O timeouts in attach fairings.

Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
2020-10-26 13:29:36 -07:00
Sergio Benitez 09f0087034 Split server parts of 'Rocket' into 'server.rs'. 2020-10-22 18:00:07 -07:00
Sergio Benitez 198b6f0e97 Fix various broken rustdoc links. 2020-10-22 03:53:07 -07:00
Sergio Benitez 08510302da Add 'Rocket::catchers()', rearrange other getters. 2020-10-22 03:41:02 -07:00
Sergio Benitez ec9b5816a8 Remove 'rocket::inspect()', 'Cargo'.
This commit reverts most of dea940c7 and d89c7024. The "fix" is to run
attach fairings on a new thread. If a runtime is already running, it is
used. Otherwise, the future is executed in a single-threaded executor.
2020-10-22 03:27:04 -07:00
Sergio Benitez 17fd7f4286 Update minimum rustc to 1.46. 2020-10-21 19:56:12 -07:00
Sergio Benitez bbfe2ba5cc Point all docs and doc links to 'master' branch. 2020-10-21 04:54:24 -07:00
George Cheng 0673986c32 Impl 'FromRequest' for 'IpAddr'.
Closes #1414.
2020-10-20 20:51:26 -07:00
ThouCheese 080d586a35 Impl 'DerefMut' for 'Form', 'LenientForm'. 2020-10-20 20:45:43 -07:00
est31 b18cd6460e Add AVIF (image/avif) as a known media type. 2020-10-20 20:40:18 -07:00
Sergio Benitez 730a2dcdbe Implement 'Serialize' for 'Flash'.
Resolves #184.
2020-10-20 20:29:55 -07:00
Sergio Benitez 7337321efb Take '&mut Data' in 'on_request' fairings.
Resolves #1438.
2020-10-20 20:22:32 -07:00
Sergio Benitez 1fb061496d Revamp configuration.
This commit completely overhauls Rocket's configuration systems, basing
it on the new Figment library. It includes many breaking changes
pertaining to configuration. They are:

  * "Environments" are replaced by "profiles".
  * 'ROCKET_PROFILE' takes the place of 'ROCKET_ENV'.
  * Profile names are now arbitrary, but 'debug' and 'release' are given
    special treatment as default profiles for the debug and release
    compilation profiles.
  * A 'default' profile now sits along-side the meta 'global' profile.
  * The concept of "extras" is no longer present; users can extract any
    values they want from the configured 'Figment'.
  * The 'Poolable' trait takes an '&Config'.
  * The 'secrets' feature is disabled by default.
  * It is a hard error if 'secrets' is enabled under the 'release'
    profile and no 'secret_key' is configured.
  * 'ConfigBuilder' no longer exists: all fields of 'Config' are public
    with public constructors for each type.
  * 'keep_alive' is disabled with '0', not 'false' or 'off'.
  * Inlined error variants into the 'Error' structure.
  * 'LoggingLevel' is now 'LogLevel'.
  * Limits can now be specified in SI units: "1 MiB".

The summary of other changes are:

  * The default config file can be configured with 'ROCKET_CONFIG'.
  * HTTP/1 and HTTP/2 keep-alive configuration is restored.
  * 'ctrlc' is now a recognized config option.
  * 'serde' is now a core dependency.
  * TLS misconfiguration errors are improved.
  * Several example use '_' as the return type of '#[launch]' fns.
  * 'AdHoc::config()' was added for simple config extraction.
  * Added more documentation for using 'Limits'.
  * Launch information is no longer treated specially.
  * The configuration guide was rewritten.

Resolves #852.
Resolves #209.
Closes #1404.
Closes #652.
2020-10-20 19:21:56 -07:00
Sergio Benitez 8da034ab83 Update 'devise'. 2020-10-15 01:01:30 -07:00
Sergio Benitez 5615767ca6 Add proper 'cfg' to 'get_private_pending()'. 2020-10-15 00:46:30 -07:00
Sergio Benitez 5cf249581f Add 'const' constructor for 'MediaType'. 2020-10-14 23:54:37 -07:00
Sergio Benitez 079e458b62 Add (un)tracked 'Client' integration tests. 2020-10-14 21:47:42 -07:00
Sergio Benitez 5d9035ddc1 Keep an op-log for sync 'CookieJar'.
In brief, this commit:

  * Updates to the latest upstream 'cookie', fixing a memory leak.
  * Make changes to 'CookieJar' observable only through 'pending()'.
  * Deprecates 'Client::new()' in favor of 'Client::tracked()'.
  * Makes 'dispatch()' on tracked 'Client's synchronize on cookies.
  * Makes 'Client::untracked()' actually untracked.

This commit updates to the latest 'cookie' which removes support for
'Sync' cookie jars. Instead of relying on 'cookie', this commit
implements an op-log based 'CookieJar' which internally keeps track of
changes. The API is such that changes are only observable through
specialized '_pending()' methods.
2020-10-14 21:37:16 -07:00
Sergio Benitez 2f330d2967 Allow return type of '#[launch]' fn to be elided. 2020-10-12 22:32:02 -07:00
Sergio Benitez 092e03f720 Generate a proxy structure for better namespacing.
Prior to this commit, it was impossible to 'use' a route from a separate
namespace for use in a 'routes!' macro. Naturally, this was a common
source of confusion amongst users. This commit obviates this deficiency
by generating a "proxy" structure that can be imported and converted
into a 'Route'/'Catcher' or their static variants.

This change is largely backwards compatible but can break existing code
when routes are named identically to other types in the namespace.
2020-10-12 22:11:44 -07:00
Edwin Svensson 29f4726127 Fix typo in 'Form::into_inner' docs: unclosed codeblock. 2020-10-11 12:49:18 -07:00
Jeb Rosen 83a7fc48d2 Update UI tests for latest nightly. 2020-10-11 12:21:45 -07:00
Sergio Benitez 1369dc47a3 Update 'atomic' and 'ubyte' dependencies. 2020-09-11 01:20:44 -07:00
Sergio Benitez adbf1caab2 Migrate to upstream 'uncased'. 2020-09-11 01:13:55 -07:00
Sergio Benitez f7eacb6a65 Tidy 'form_value_from_encoded_str' test. 2020-09-10 02:15:29 -07:00
lewis 53d13a309b Decode in 'FromFormValue' as needed by 'FromStr'.
Fixes #1425.
2020-09-10 02:07:54 -07:00
Jeb Rosen f976c15c25 Update UI tests for latest nightly. 2020-09-06 18:34:24 -07:00
Jeb Rosen dc2c6ecd8a Update UI tests for latest stable. 2020-08-31 18:51:38 -07:00
Sergio Benitez 52320020bc Use thread-safe 'CookieJar's.
The user-facing changes effected by this commit are:

  * The 'http::Cookies<'_>' guard is now '&http::CookieJar<'_>'.
  * The "one-at-a-time" jar restriction is no longer imposed.
  * 'CookieJar' retrieval methods return 'http::CookieCrumb'.
  * The 'private-cookies' feature is now called 'secrets'.
  * Docs flag private cookie methods with feature cfg.
  * Local, async request dispatching is never serialized.
  * 'Client::cookies()' returns the tracked 'CookieJar'.
  * 'LocalResponse::cookies()' returns a 'CookieJar'.
  * 'Response::cookies()' returns an 'impl Iterator'.
  * A path of '/' is set by default on all cookies.
  * 'SameSite=strict' is set by default on all cookies.
  * 'LocalRequest::cookies()' accepts any 'Cookie' iterator.
  * The 'Debug' impl for 'Request' prints the cookie jar.

Resolves #1332.
2020-08-16 02:19:45 -07:00
Sergio Benitez 549c9241c4 Require data limits on 'Data::open()'.
Closes #1325.
2020-08-06 02:46:04 -05:00
Sergio Benitez 45b4436ed3 Add default catchers: '#[catch(default)]'.
The bulk of the changes in this commit are for creating an
'ErrorHandler' trait that works like the 'Handler' trait, but for
errors. Furthermore, Rocket's default catcher now responds with a JSON
payload if the preferred 'Accept' media type is JSON.

This commit also fixes a bug in 'LocalRequest' where the internal
'Request' contained an correct 'URI'.
2020-07-30 01:55:41 -07:00
Sergio Benitez e531770989 Make URI modifications to 'Route' codegen-safe.
This commit aims to make it impossible to modify a 'Route' structure in
a way that violates expectations of a code-generated 'Route'. It removes
'Route::set_uri()' in favor of 'Route::map_base()', which allows for
safe modifications of the route's base.

In a similar vain, this commit also includes the following changes:

  * 'Route::path()' was added to safely retrieve the route's 'path'.
  * The base of a 'Route' is underlined during launch printing.
  * 'Origin::into_normalized()' replaces 'Origin::to_normalized()'.

Fixes #1262.
2020-07-29 16:38:24 -07:00
Jonathan Dickinson f3beb68491 Remove superfluous lifetimes in 'Fairing' methods. 2020-07-23 21:32:20 -07:00
Sergio Benitez 754b1e0e31 Panic if 'StaticFiles' directory doesn't exist. 2020-07-23 20:12:20 -07:00
Sergio Benitez 261cb400d1 Don't use managed state to thread 'Shutdown'. 2020-07-22 19:22:32 -07:00
Sergio Benitez adc79016cd Rearrange top-level exports. Use '#[launch]'.
This commits makes the following high-level changes:

  * 'ShutdownHandle' is renamed to 'Shutdown'.
  * 'Rocket::shutdown_handle()' is renamed to 'Rocket::shutdown()'.
  * '#[launch]` is preferred to '#[rocket::launch]'.
  * Various docs phrasings are improved.
  * Fixed various broken links in docs.

This commits rearranges top-level exports as follows:

  * 'shutdown' module is no longer exported.
  * 'Shutdown' is exported from the crate root.
  * 'Outcome' is not longer exported from the root.
  * 'Handler', 'ErrorHandler' are no longer exported from the root.
2020-07-22 16:10:02 -07:00
Necmettin Karakaya fde6eda915 Fix various typos throughout the codebase. 2020-07-22 12:56:01 -07:00
Jeb Rosen 8d779caa22 Note lower ranks are higher precedence in 'Route'.
Fixes #1360.
2020-07-22 12:28:56 -07:00
Sergio Benitez ddfd73d6f3 Delete broken symlinks to 'update-references.sh'.
Fixes #1385.
2020-07-22 06:52:04 -07:00
Sergio Benitez 56a6172625 Enable compilation with stable Rust.
To the Rust teams, Rust's contributors, Rocket's contributors, the
entire Rust and Rocket communities, my colleagues at Stanford and
beyond, and Jeb: thank you all. Sincerely.

To the next ~4 years of Rocket!

Closes #19.
2020-07-21 16:30:45 -07:00
Sergio Benitez b47d1b8f0f Rework docs for stable and async support. 2020-07-21 16:15:13 -07:00
Sergio Benitez cd7e99a535 Use 'bencher' for benchmarks on stable. 2020-07-21 15:31:44 -07:00
Sergio Benitez 9a2149b43d Test guide and README using stable 'doc_comment'. 2020-07-21 15:31:44 -07:00
Sergio Benitez 67efe143c5 Improve diagnostics, especially on stable. 2020-07-21 15:31:42 -07:00
Sergio Benitez 1858403203 Implement codegen testing on stable.
This commits migrates to 'trybuild' from 'compiletest' for codegen
diagnostic testing.
2020-07-21 15:11:07 -07:00
Sergio Benitez 95a4b442cc Update Pear to 0.2. 2020-07-21 15:11:07 -07:00
Jeb Rosen 27b26188c4 Update 'toml' to '0.5'. 2020-07-21 15:11:07 -07:00
Jeb Rosen fb42bf9ee2 Upgrade 'tokio-rustls' to 0.14. 2020-07-21 10:54:07 -07:00
Jakub Wieczorek 6f1cefff10 Upgrade 'percent-encoding' to 2.
Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
2020-07-21 10:54:07 -07:00
Jeb Rosen 7f276eb2fc Update 'devise' to the latest commit. 2020-07-20 23:26:36 -07:00
Sergio Benitez 0909ba2ef6 Only enable testing features on 'cfg(test)'. 2020-07-16 05:49:38 -07:00
Sergio Benitez 3f2b8f6006 Remove 'proc_macro' features. 2020-07-16 05:46:39 -07:00
Sergio Benitez 7bcf82a199 Improve catcher mismatched type errors. 2020-07-14 02:48:46 -07:00
Sergio Benitez dfca18d307 Generate 'uri!' macro names independently of span.
Prior to this commit, codegen used 'Span' information to generate a
unique id for a given route. This commit changes the id generation to
instead use 1) the route's name and path, 2) a an per-generation
atomically increasing ID, and 3) the ids of the process/thread the
proc-macro is running in. Together, these values should provide a unique
id for a given route, even in the face of the reused processes and
threads, while also removing the dependence on unstable Span features.

Fixes #1373.
2020-07-14 00:44:59 -07:00
Sergio Benitez 816b8c44ab Ignore 'snake_case' warnings for 'tmp' variables. 2020-07-14 00:43:48 -07:00
Sergio Benitez a87e3ad9f5 Remove superfluous empty lines. 2020-07-12 02:38:28 -07:00
Sergio Benitez 33e95f4900 Rename 'FromDataSimple' to 'FromData'. Make async.
The 'FromData' trait becomes 'FromTransformedData'.
2020-07-12 02:23:00 -07:00
Sergio Benitez f4c82d7ffe Remove unnecessary 'dev-dependencies'. 2020-07-11 11:27:23 -07:00
Sergio Benitez 62355b424f Remove use of stable 'proc_macro_hygiene' feature. 2020-07-11 10:48:08 -07:00
Sergio Benitez 08b34e8263 Fix and re-enable UI tests. 2020-07-11 09:24:30 -07:00
Sergio Benitez 832408ea9b Add example requiring async testing. 2020-07-11 09:24:30 -07:00
Jeb Rosen 06975bfaea Use the blocking testing API everywhere.
Co-authored-by: Sergio Benitez <sb@sergio.bz>
2020-07-11 09:24:30 -07:00
Sergio Benitez 6482fa2fba Rework 'local' module. Add 'LocalResponse' methods.
This completes the 'local' blocking client implementation.
2020-07-11 09:24:30 -07:00
Jeb Rosen 050a2c6461 Document new 'local' structures. 2020-07-11 09:24:30 -07:00
Sergio Benitez 03127f4dae Add blocking variant of 'local'.
This commit adds the 'local::blocking' module and moves the existing
asynchronous testing to 'local::asynchronous'. It also includes several
changes to improve the local API, bringing it to parity (and beyond)
with master. These changes are:

  * 'LocalRequest' implements 'Clone'.
  * 'LocalResponse' doesn't implement 'DerefMut<Target=Response>'.
    Instead, direct methods on the type, such as 'into_string()', can
    be used to read the 'Response'.
  * 'Response::body()' returns an '&ResponseBody' as opposed to '&mut
    ResponseBody', which is returned by a new 'Response::body_mut()'.
  * '&ResponseBody' implements 'known_size()` to retrieve a body's size,
    if it is known.

Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
2020-07-11 09:24:30 -07:00
Sergio Benitez 824de061c3 Enable configurable 'ctrl-c' shutdown by default.
This removes the 'ctrl_c_shutdown' feature opting instead for a 'ctrlc'
configuration option. To avoid further merge conflicts with the master
branch, the option is currently read as an extra.

Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
2020-07-11 09:24:30 -07:00
Sergio Benitez 9277ddafdf Swap 'Rocket' manually without using 'replace_with'. 2020-07-11 09:24:30 -07:00
Sergio Benitez 3ced188f7d Use 'ref-cast' for safer transparent casting. 2020-07-11 09:24:30 -07:00
Sergio Benitez d89c7024ed Replace 'Manifest' with 'Cargo'.
This is largely an internal change. Prior to this commit, the 'Manifest'
type, now replaced with the 'Cargo' type, robbed responsibility from the
core 'Rocket' type. This new construction restores the previous
responsibility and makes it clear that 'Cargo' is _only_ for freezing,
and representing the stability of, Rocket's internal state.
2020-07-11 09:24:30 -07:00
Sergio Benitez dd5b518cc2 Ignore 'unused_imports' warning on cfg-based 'FutureExt'. 2020-07-11 09:24:30 -07:00
Sergio Benitez 1704ff7743 Asyncify 'Handler'. Rename 'ErrorHandlerFuture' to 'CatcherFuture'. 2020-07-11 09:24:30 -07:00
Sergio Benitez f7cd455558 Make 'NamedFile' async. Fix 'Handler' trait.
Previously, 'NamedFile::open()' called a synchronous I/O method. This
commit changes it to instead use tokio's 'File' for async I/O.

To allow this to change, the 'Handler' trait was fixed to enforce that
the lifetime of '&self', the reference to the handler, outlives the
incoming request. As a result, futures returned from a handler can hold
a reference to 'self'.
2020-07-11 09:24:30 -07:00
Sergio Benitez 2465e2f136 Make 'Responder' trait sync; fix its lifetimes.
In summary, this commit modifies 'Responder' so that:

  * ..it is no longer 'async'. To accommodate, the 'sized_body' methods
    in 'Response' and 'ResponseBuilder' are no longer 'async' and accept
    an optional size directly. If none is supplied, Rocket will attempt
    to compute the size, by seeking, before writing out the response.
    The 'Body' type was also changed to differentiate between its sized
    'Seek' and chunked body variants.

  * ..'&Request' gains a lifetime: 'r, and the returned 'Response' is
    parameterized by a new 'o: 'r. This allows responders to return
    references from the request or those that live longer.
2020-07-11 09:24:29 -07:00
Sergio Benitez 12308b403f Add '#[rocket::launch]' attribute.
The attribute is applied everywhere it can be across the codebase and is
the newly preferred method for launching an application. This commit
also makes '#[rocket::main]` stricter by warning when it is applied to
functions other than 'main'.
2020-07-11 09:24:29 -07:00
Jeb Rosen c7c371910b Remove extraneous dependency on 'futures-util'. 2020-07-11 09:24:29 -07:00
Jeb Rosen bc1b90cbdb Add '#[rocket::main]' attribute and make 'launch()' an 'async fn'.
'#[rocket::main]' works like '#[rocket::async_test]', but it uses
tokio's multithreaded scheduler.
2020-07-11 09:24:29 -07:00
Jeb Rosen 7a62653cdd Add a test verifying that attempting to manage the same state type twice panics. 2020-07-11 09:24:29 -07:00
Jeb Rosen e72058de81 Add 'config()' and 'state()' functions directly to 'Rocket' for convenience. 2020-07-11 09:24:29 -07:00
Jeb Rosen b0238e5110 Make 'Fairing::on_attach()' async.
This transitively requires that 'Rocket::inspect()', 'Client::new()',
and 'Client::untracked()' also become async.
2020-07-11 09:24:29 -07:00
Jeb Rosen dea940c7a8 Defer execution of operations on 'Rocket' until their effects will be
observed.

This is a prerequisite for async on_attach fairings. 'Rocket' is now a
builder wrapper around the 'Manifest' type, with operations being
applied when needed by 'launch()', 'Client::new()', or 'inspect()'.
'inspect()' returns an '&Manifest', which now provides the methods that
could be called on an '&Rocket'.
2020-07-11 09:24:29 -07:00
Sergio Benitez 8696dd94af Make references to core types absolute in codegen.
Prior to this commit, codegen emitted tokens containing bare types like
'Result' and 'Box' as well as presumed imported variants such as 'None'
and 'Ok'.  However, users are free to shadow these, and if they do, the
generated code will fail to compile, or worse, be incorrect. To avoid
this, this commit makes all references to these core types and imports
absolute.
2020-07-11 09:24:29 -07:00
Jeb Rosen 71b888c2fa Fix AddrParseError when the incoming connection's remote_addr is not known. 2020-07-11 09:24:29 -07:00
Jeb Rosen 2ca15b663a Update minimum nightly to '2019-12-29'.
This version of rustc was the first to ship with a version of cargo that
supports 'proc_macro' without an 'extern crate' declaration.
2020-07-11 09:24:29 -07:00
Sergio Benitez 98a90808b4 Fix an array of broken doc links. 2020-07-11 09:24:29 -07:00
Sergio Benitez c0c6c79a7f Use 'async_trait' for 'Responder'.
Also:

  * Remove 'response::ResultFuture'.
  * Re-export 'tokio' and 'futures' from the crate root.
  * Make 'ResponseBuilder::sized_body()' and 'async fn'.
  * Remove the 'Future' implementation for 'ResponseBuilder'.
  * Add 'ResponseBuilder::finalize()' for finalizing the builder.
2020-07-11 09:24:29 -07:00
Sergio Benitez 58f81d392e Simplify async 'Response' methods. 2020-07-11 09:24:29 -07:00
Sergio Benitez 431b963774 Use 'async_trait' for 'FromRequest'.
Removes 'FromRequestAsync'.
2020-07-11 09:24:29 -07:00
Sergio Benitez 48c333721c Use 'async_trait' for 'Fairing' trait.
Also re-exports the 'async_trait' attribute from 'rocket'.
2020-07-11 09:24:29 -07:00
Sergio Benitez a4e7972b4b Remove unnecessary 'extern crate's. 2020-07-11 09:24:29 -07:00
Sergio Benitez 73484f1a88 Implement 'Responder' for 'tokio::fs::File'. 2020-07-11 09:24:29 -07:00
Michael Howell 5f3baf240a Deduplicate response streaming code for sized and chunked bodies. 2020-07-11 09:24:29 -07:00
Jeb Rosen d5483cb196 Clean up Error handling.
* Implement `std::error::Error` for the new Error type.
* Document the new Error type.
* Remove `LaunchError`'s implementation of `Error::description`, which is deprecated.
2020-07-11 09:24:29 -07:00
Jeb Rosen 85761c08e3 Fix deprecation warning: 'tokio::runtime::Builder::num_threads' -> 'core_threads'. 2020-07-11 09:24:29 -07:00
Michael Howell c9d0af09d6 Use 'AsyncSeek' for sized bodies in 'Response's.
In order to avoid making 'ResponseBuilder::sized_body' an asynchronous
function, the seeking is deferred until finalization. 'finalize()' is
replaced with '.await', and 'ResponseBuilder::ok()' is an 'async fn'.
2020-07-11 09:24:29 -07:00
Jeb Rosen dcd4068ca0 Move a debug-only 'use' in 'from_data.rs' to the locations where it is actually used. 2020-07-11 09:24:29 -07:00
Jeb Rosen e41abc09e5 Update more API documentation to mention futures and async. 2020-07-11 09:24:29 -07:00
Jeb Rosen 9a16aeb2e0 Use async fn instead of impl Future in a few methods in 'Data' and 'Rocket'. 2020-07-11 09:24:29 -07:00
Jeb Rosen f442642ec2 Fix request URI tests. 2020-07-11 09:24:29 -07:00
Jeb Rosen 49f4641871 Clean up handling of body data:
* Minor code and comment tweaks
* Remove dynamic dispatch inside Data and DataStream
2020-07-11 09:24:29 -07:00
Jeb Rosen 571e2ac845 Revert incoming request URI and header parsing to more closely match 0.4. 2020-07-11 09:24:29 -07:00
Jeb Rosen c2da8a21d8 Change a panic to an error when a client sends a request but disconnects before a response can be sent. 2020-07-11 09:24:29 -07:00
Jeb Rosen 70096c1bd4 Revert on_response lifetimes to more closely match 0.4. 2020-07-11 09:24:29 -07:00