Commit Graph

266 Commits

Author SHA1 Message Date
Jacob Pratt bd929ef617 Remove unnecessary boxing of some Futures. 2020-07-11 09:24:28 -07:00
Jacob Pratt 1f90a9b6d1 Update hyper to '=0.13.0-alpha.1'. 2020-07-11 09:24:28 -07:00
Jeb Rosen 047b1620f9 Update pinned hyper and tokio versions. 2020-07-11 09:24:28 -07:00
Jacob Pratt 05426881b0 Use 'File' from 'async_std' instead of from 'tokio'.
Additionally pin tokio to '=0.2.0-alpha.2'; before this change cargo
selects '0.2.0-alpha.3' which hyper does not compile against.
2020-07-11 09:24:28 -07:00
Jeb Rosen 560f0977d3 Revamp testing system for async.
* body_string_wait and body_bytes_wait are removed; use `.await` instead
* `dispatch()` is now an async fn and must be .await-ed
* Add `#[rocket::async_test]` macro, similar in purpose to `tokio::test`
* Tests now use either `rocket::async_test(async { })` or
  `#[rocket::async_test]` in order to `.await` the futures returned
  from `dispatch()` and `body_{string,bytes}()`
* Update 'test.sh' to reflect the tests that should be passing.

Broken:

* Cloned dispatch and mut_dispatch() with a live previous response now both fail, due to a (partial) check for mutable aliasing in LocalRequest.
* Some tests are still failing and need example-specific changes.
2020-07-11 09:24:28 -07:00
Jacob Pratt a87e1577aa Add 'Rocket::spawn_on' to spawn a server on a user-provided (tokio) runtime. 2020-07-11 09:24:28 -07:00
Jacob Pratt e44c5896b8 Remove stabilized 'async_await' feature gate and update the minimum nightly version. 2020-07-11 09:24:28 -07:00
Jeb Rosen af95129590 Use futures 0.3-compatible hyper and tokio and the tokio runtime instead
of futures-rs executor.

Despite this change, using body_bytes_wait on (for example) a File will
still fail due to tokio-rs/tokio#1356.
2020-07-11 09:24:28 -07:00
Jeb Rosen 8c8598b4fd Fix 'static_files' and 'serve' tests. 2020-07-11 09:24:28 -07:00
Jeb Rosen b780f9d8e0 Fix or ignore remaining doc tests in 'core'.
This adds an unstable "async_test" function for use in tests, to ensure
they stay working while refactoring other APIs.
2020-07-11 09:24:28 -07:00
Jeb Rosen aee7f35095 Use read_to_string (from futures-preview 0.3.0-alpha.18) to more closely match the pre-async code. 2020-07-11 09:24:28 -07:00
Jacob Pratt 0e6841da66 Convert two internal functions returning `Pin<Box<_>>` to `async fn`. 2020-07-11 09:24:28 -07:00
Jeb Rosen b56e889a0e Disable some known-failing tests for now. 2020-07-11 09:24:28 -07:00
Jeb Rosen 633e495a6b Update many doc tests in 'core' for async. 2020-07-11 09:24:28 -07:00
Jeb Rosen 1601e5c814 Fix a few 'unused use' warnings. 2020-07-11 09:24:28 -07:00
Jeb Rosen 6044961680 Update parts of contrib and associated tests and examples:
* json
  * templates
  * helmet
  * databases
  * serve
  * examples/cookies
  * examples/handlebars_templates
  * examples/json
  * examples/session
  * examples/static_files
  * examples/tera_templates
2020-07-11 09:24:28 -07:00
Jeb Rosen 7c34a3a93e Make 'Fairing::on_response' and 'Responder::respond_to' async.
This is required to be able to do anything useful with the body in the
outgoing response. Request fairings do not appear to need to be async
as everything on Data that returns a future moves self and on_request only
gets &Data, but the same change in this commit should work for on_request
if desired.
2020-07-11 09:24:28 -07:00
Jeb Rosen 5d439bafc0 Convert core to async and add support for async routes.
Minimum rustc bump required for rust-lang/rust#61775
2020-07-11 09:24:28 -07:00
Marc Schreiber 96b4142156 Upgrade to hyper 0.12.
* Use hyper's 'MakeService' implementation with futures API.
  * Use tokio runtime to serve HTTP backend.
2020-07-11 09:24:03 -07:00
Sergio Benitez 263e39b5b4 Always override config defaults with env vars.
Fixes a regression introduced in f7b1089.
2020-07-08 19:39:28 -07:00
gcarq 86d0bdddb2 Replace manual ASCII checks with 'std::char' calls. 2020-06-22 05:07:14 -07:00
Sergio Benitez 83925bbae1 Use clearer variables names in guide test macro.
Also removes latent, unnecessary 'guide' test.
2020-06-14 18:56:45 -07:00
Sergio Benitez 74f15a7ab5 Use top-level doc image URLs. 2020-06-11 02:30:14 -07:00
Sergio Benitez f7b1089b49 Allow setting config path via 'ROCKET_CONFIG_FILE'. 2020-06-07 03:46:43 -07:00
Sergio Benitez a4301c0a9a Add 'Config::read()' and 'Config::read_from()'.
The former method allows constructing a 'Config' in the exact manner
Rocket does internally: reading the active environment's properties from
'Rocket.toml' and overriding values from environment variables. The
'read_from()' property does the same except it allows a custom config
file path.

This PR also improves the internal structure of the configuration code.
2020-06-07 02:42:15 -07:00
Sergio Benitez 3f20e4ac93 Use proper SPDX license expression in 'Cargo.toml'. 2020-06-03 23:02:05 -07:00
Jeb Rosen 097fbd7df0 Fix some broken links in API documentation. 2020-05-31 11:32:14 -07:00
Yusuke Kominami a21221aeb6 Replace deprecated 'OffsetDateTime::now' with 'OffsetDateTime::now_utc'.
Update 'time' dependency accordingly.
2020-05-30 11:13:40 -07:00
Nia Watts ea81f8e07b Fix typo in 'Query' documentation: 'mplementation' -> 'implementation'. 2020-05-30 11:09:42 -07:00
Sergio Benitez ee5988fe5c Update 'cookie' to '0.14'. 2020-05-30 01:49:32 -07:00
Sergio Benitez b8f9011c04 Fix 'LocalRequest::clone()' soundness issue.
The existing implementation of 'LocalRequest::clone()' mistakenly copied
the internal 'Request' pointer from the existing 'LocalRequest' to the
cloned 'LocalRequest'. This resulted in an aliased '*mut Request'
pointer, a clear soundness issue. The fix in this commit is to clone the
internal 'Request', replacing the internal pointer with the newly cloned
'Request' when producing the cloned 'LocalRequest'. A fix that removes
all 'unsafe' code should be explored.

Fixes #1312.
2020-05-27 01:09:12 -07:00
Alex Macleod ca4d1572d4 Hide emoji on Windows.
Closes #1122.
2020-05-17 15:30:48 -07:00
Sergio Benitez a8b029e423 Properly delimit length and name in flash cookies.
Fixes #1263.
2020-05-16 17:55:54 -07:00
Thiago Veronezi 94a222f6fe Fix typo in 'State' documentation: missing backtick. 2020-04-21 18:47:17 -07:00
Sergio Benitez 06e146e7d1 Update 'time' to 0.2 in 'contrib'. 2020-03-25 14:39:55 -07:00
Sergio Benitez 53353df633 Fix more broken links. 2020-03-09 02:03:38 -07:00
Sorin Davidoi dfc9e9aab0 Improve accessibility of default error HTML. 2020-03-02 16:39:19 -08:00
Sergio Benitez 32e86c3b69 Inline macro docs into core crate. 2020-02-25 16:56:59 -08:00
Sergio Benitez 95c981de79 Test all guide code examples.
Every code example is now fully runnable and testable. As a result, all
examples are now tested and include imports. Relevant imports are shown
by default. Code examples can be expanded to show all imports.

Fixes #432.
2020-02-15 04:02:19 -08:00
Sergio Benitez 385b69cf69 Migrate to 'binascii' for base 16, 64 decoding. 2020-02-14 17:14:37 -08:00
Sergio Benitez f35e3c4aca Set cookies even on error responses.
Fixes #1213.
2020-01-23 21:10:04 -08:00
Sergio Benitez 7c1b8dc9ad Update 'cookie' to 0.13, 'rustls' to 0.16. 2020-01-21 16:10:04 -08:00
A. L 859224a209 Add additional Responder wrappers for some common HTTP status codes:
* 204 NoContent
* 401 Unauthorized
* 403 Forbidden
* 409 Conflict
2020-01-15 11:41:19 -08:00
Paolo Barbolini cd5f96ae15 Update 'uuid', 'unicode-xid', and 'base64' dependencies. 2019-11-30 09:33:14 -08:00
Michael Howell 121210c55c Add support for base16-encoded (a.k.a. hex-encoded) secret keys. 2019-11-29 12:06:55 -08:00
Jeb Rosen e7e84a6d41 Fix and update benchmarks. 2019-11-16 13:08:36 -08:00
Jacob Pratt 4e6a7ddd5f Remove use of the 'crate_visibility_modifier' feature.
Most items with 'crate' visibility become 'pub(crate)'.
Items are made 'pub' instead when they would remain private.
2019-09-21 09:16:04 -07:00
Jacob Pratt bed93133b8 Abide by formatting in 'Debug' implementations. 2019-09-18 19:06:08 -07:00
Jacob Pratt e3c1a4ad3a Remove use of the 'try_trait' feature.
Add the 'try_outcome' macro to replace uses of '?' on 'Outcome'.
2019-09-18 18:43:16 -07:00
Jacob Pratt b95b6765e1 Remove use of 'label_break_value' feature. 2019-09-10 17:27:40 -07:00
Sergio Benitez 2537a1164d Remove 'Result' specialization. Add 'Debug' responder.
This removes all uses of specialization in Rocket.
2019-09-09 21:57:33 -07:00
Sergio Benitez 3fae9919f7 Deprecate 'Result<T, E>, E: !Responder' responder. 2019-09-09 21:56:55 -07:00
Sergio Benitez c5973f01df Remove use of specialization in 'status::Created'. 2019-09-09 16:37:46 -07:00
Jeb Rosen 3e4f8453ce Remove use of the 'decl_macro' feature.
Also removes one internal use in the 'typed-uris' codegen test.
2019-07-19 11:39:56 -07:00
Jacob Pratt 34a741a26e Remove use of '!' type in favor of 'Infallible'.
This removes the use of and dependence on the 'never_type' feature.
2019-07-09 15:10:51 -07:00
Sergio Benitez 21b10176ee Forward from 'StaticFiles' if a file is not found.
Also adds a 'handler::Outcome::from_or_forward' method for easily
constructing handler outcomes that forward on responder failures.

Fixes #1036.
2019-07-07 23:22:38 -07:00
Dmitry Murzin c100a92127 Implement 'FromParam' for 'NonZero*' types. 2019-07-06 13:32:08 -07:00
Sergio Benitez 7f2c9f426c Fix tests for Windows. 2019-07-06 00:59:01 -07:00
Jeb Rosen 34cb1c14b8 Migrate core to Rust 2018. 2019-06-25 13:45:23 -04:00
Thomas Lent 42f8af411e Fix type in 'Data' rustdocs: 'T' -> 'DataGuard'. 2019-06-11 15:04:54 -07:00
Sergio Benitez e458df094f Update 'version_check' to 0.9. 2019-05-24 01:48:42 -07:00
jeb 6bf751fb22 Reexport derive macros alongside derived traits. 2019-05-22 22:19:47 -07:00
Sergio Benitez 1caf87eb21 Move to 0.5.0-dev on master. 2019-05-13 16:18:48 -07:00
Richard Petrie 75d2ea96d9 Replace deprecated 'isatty' with 'atty'. 2019-05-10 18:21:58 -07:00
Sergio Benitez 3e7a20ae57 Clarify defaults in 'Config' documentation. 2019-05-10 16:39:41 -07:00
Sergio Benitez fdd76ecf7e Clean up 'AdHoc' fairing implementation. 2019-05-09 09:04:31 -07:00
Sergio Benitez 7c2dda2647 Clean up 'Server' header commentary. 2019-05-08 20:20:26 -07:00
Sergio Benitez 9f75e0f443 Clean up 'conditionally-set-server-header' test. 2019-05-08 20:18:10 -07:00
lu4nm3 0a978fdb5d Set default 'Server' header only if it isn't set.
Closes #996.
2019-05-08 20:18:10 -07:00
Konrad Borowski 7ab1c427b5 Replace uses of `FnBox`; `Box<dyn FnOnce>` now implements `FnOnce`. 2019-04-13 09:15:27 -07:00
Jacob Pratt 9b219ddc01 Remove stabilized feature gates.
* try_from
* transpose_result
2019-04-12 18:48:51 -07:00
Sergio Benitez de9a98edd2 Update 'Rocket::custom()' docs to match signature.
Resolves #910.
2019-02-06 17:18:53 -08:00
Chris Foster 4921af459f Fix typo in 'LenientForm' docstring: 'gaurd' -> 'guard'. 2019-01-31 20:15:10 -08:00
Sergio Benitez ca5623c641 Type encoding to fix encoding issues once and for all.
Fixes #849.
2018-12-12 17:38:36 -08:00
Sergio Benitez a4dcb0cf4c New version: 0.4.0. 2018-12-06 09:19:11 -08:00
Sergio Benitez 90a6749313 New version: 0.4.0-rc.2. 2018-11-30 21:00:18 -08:00
Sergio Benitez 7919ceac39 Strip dev-dependencies more reliably. 2018-11-30 20:58:29 -08:00
Sergio Benitez 5ec21d5ba0 Update dependencies to published versions. 2018-11-30 09:00:16 -08:00
Sergio Benitez b7db74144f Parameterize 'UriDisplay' with 'Path' or 'Query'.
This commit introduces the sealed `UriPart` marker trait as well as the
implementing `Path` and `Query` marker types, allowing for parts of a
URI to be distinguished at the type level. Consequently, `UriDisplay`
has been parameterized with `P: UriPart`, creating `UriDisplay<Path>`
and `UriDisplay<Query>`. The effect of this change is improved type
safely for URI rendering as well as the ability to omit rendering values
in query parts via `Option` and `Result`.

The `UriDisplay` derive was replaced by `UriDisplayQuery` and
`UriDisplayPath` which derive implementations for `UriDisplay<Path>`
and `UriDisplay<Query>`, respectively.

This commit also works around a rustdoc visibility issue by creating a
hidden `http::private` module.

Finally, this commit also removes the now vestigial use of the
`rustc_private` feature in codegen.

Fixes #827.
2018-11-27 10:01:47 -06:00
Sergio Benitez abb434f228 Stop using white for legible logging everywhere.
Prior to this change, Rocket emitted "white" text in much of its logging
output. On terminals with light backgrounds, the text was nearly
illegible. This PR stops using white coloring altogether, opting instead
to use the terminal's default color albeit with bold styling. On dark
terminals, this will likely be a light color, and on light terminals,
this will likely be a dark color. The end result is that Rocket's
logging output should be readable everywhere.

Resolves #639.
2018-11-19 02:11:38 -08:00
Sergio Benitez 76c830a467 Update 'base64', 'crossbeam', 'rand' dependencies. 2018-11-18 03:47:12 -08:00
Sergio Benitez 3b6c4d2a5f Prefix codegen imports to avoid name collisions.
Fixes #817.
2018-11-12 13:08:39 -08:00
Sergio Benitez 834c91ae9d Remove the need for a current working directory.
This commit includes several breaking changes:

  * `Config{new,development,staging,production}` constructors return a
    `Config` instead of a `Result<Config>`.
  * `Config.root()` returns an `Option<&Path>` instead of `&Path`.
  * `ConfigError::BadCWD` was removed.
  * `Config` no longer exposes a `config_path` field.

Resolves #809.
2018-11-12 02:24:13 -08:00
Alva Snædís b87994b52c Implement FromParam, FromFormValue for i128, u128. 2018-11-11 21:51:24 -08:00
Sergio Benitez 4224419e63 Reduce 'cfg' usage for 'private-cookies' feature. 2018-11-08 23:56:15 -08:00
Linus Unnebäck 53758c6dd7 Introduce the 'private-cookies' feature. 2018-11-08 23:38:18 -08:00
Sergio Benitez b16269a30e Add note about cookie tracking serialization. 2018-11-08 21:40:42 -08:00
messense 64ba2056ef Use 'RwLock' to make 'Client' 'Sync'.
Resolves #814.
2018-11-08 21:40:34 -08:00
Sergio Benitez 983ee9b32d Make inner 'LenientForm' field public. Add 'State::from()'. 2018-11-03 01:52:19 -07:00
Rukai b4f85daaf2 Make inner 'Form' field public. 2018-11-02 18:04:27 -07:00
Sergio Benitez 5762208bba Percent-encode characters: '[', ']', '\', '^', '|'.
Fixes #808.
2018-11-02 00:10:01 -07:00
Sergio Benitez 4dbd87a36f New version: 0.4.0-rc.1. 2018-10-31 14:35:30 -07:00
Sergio Benitez 41de1e62fb Implement 'Responder' for 'Status'.
This commit obviates the following removed types:

  * response::Failure
  * response::status::NoContent
  * response::status::Reset

Closes #489.
2018-10-31 03:57:22 -07:00
Sergio Benitez 7b2b6aba81 Use published version of 'pear'. 2018-10-28 20:17:44 -07:00
Sergio Benitez c1b39a016b Improve 'Redirect' and 'rocket_codegen' documentation. 2018-10-28 20:17:44 -07:00
Sergio Benitez 556206e8b3 Version all URLs to 'rocket.rs'. 2018-10-26 21:20:12 -07:00
Sergio Benitez 26db5ecb4e Fix normalization and Windows issues. 2018-10-24 00:01:56 -07:00
Sergio Benitez f6325798b1 Normalize paths in 'route_guard' test. 2018-10-23 01:23:11 -07:00
Sergio Benitez 9ef0b731c8 Rename 'codegen_next' to 'codegen'. 2018-10-22 00:01:41 -07:00
Sergio Benitez 8b2ee5b99a Point 'FromData' implementors to 'FromDataSimple'. 2018-10-21 23:43:24 -07:00
Sergio Benitez b429063279 Fix incorrect 'Data' buffering.
This regression was introduced in ad0ba0d5, where the buffer was
being copied from Hyper instead of being 'taken', resulting in
double-bufferred contents.
2018-10-21 20:36:40 -07:00
Sergio Benitez 2845b8d4d4 Add coloring disabling with 'ROCKET_CLI_COLORS=off'.
Resolves #703.
2018-10-21 19:46:37 -07:00
Sergio Benitez ad0ba0d5f1 Remove use of 'unsafe' in 'Data'. 2018-10-15 01:52:06 -07:00
Sergio Benitez 05eee14d90 Update pear to latest revision. 2018-10-14 23:49:02 -07:00
Richo Healey 085a143075 Update docstring for 'ConfigBuilder::keep_alive'. 2018-10-11 16:39:35 -07:00
Sergio Benitez e34b2f3703 Fully document all public items in core. 2018-10-10 05:28:01 -07:00
Sergio Benitez 8b1e93192e Version documentation. 2018-10-09 04:31:09 -07:00
Sergio Benitez 28f2a33abd Use inter/intra-crate links in all documentation. 2018-10-09 04:31:09 -07:00
Sergio Benitez 2839aca8ce Update features for latest nightly. 2018-10-09 04:31:09 -07:00
Sergio Benitez 360b0e80b0 Port all codegen tests to codegen_next. 2018-10-09 04:31:08 -07:00
Sergio Benitez 61f107f550 Reimplement route attribute as a proc-macro.
This commits also implement the query reform from #608. It also consists
of many, many breaking changes. Among them are:

  * Query parts in route paths use new query reform syntax.
  * Routing for queries is now lenient.
    - Default ranking has changed to reflect query reform.
  * Format routing matching has been fixed.
    - Routes with formats matching "accept" will always collide.
    - Routes with formats matching "content-type" require requests to
      have an equivalent content-type header to match.
    - Requests with imprecise content-types are treated as not having a
      content-type.
  * Generated routes and catchers respect visibility modifiers.
  * Raw getter methods from request were renamed and retooled.
    - In particular, the index parameter is based on segments in the
      route path, not dynamic parameters.
  * The method-based attributes no longer accept a keyed 'path'.
  * The 'rocket_codegen' crate is gone and will no longer be public.
  * The 'FormItems' iterator emits values of type 'FormItem'.
    - The internal form items' string can no longer be retrieved.
  * In general, routes are more strictly validated.
  * Logging from codegen now funnels through logging infrastructure.
  * Routing has been optimized by caching routing metadata.

Resolves #93.
Resolves #608.
Resolves #693.
Resolves #476.
2018-10-09 04:18:04 -07:00
Sergio Benitez cee2f4439f Fix 'content_types' example for debug-only 'FromData' impl. 2018-09-27 01:16:26 -07:00
Sergio Benitez ec4cc3a293 Allow transforms in 'FromData'. Add 'FromDataSimple'.
The new 'FromData' trait allows an implementor to instruct the caller to
maintain state on its stack and later pass a borrow for processing.
Among other things, it greatly simplifies the 'Form' type, removing a
use of unsafe, and allows references in deserialized data guards.
2018-09-26 21:33:02 -07:00
Sergio Benitez 633d37bc97 Fix invalid TOML test for updated 'toml' dependency. 2018-09-25 19:41:59 -07:00
Sergio Benitez 24ee97575b Remove Collider trait. 2018-09-24 19:44:38 -07:00
Sergio Benitez d011cd63fc Remove unnecessary 'use rocket::catch'. 2018-09-16 20:52:07 -07:00
Sergio Benitez 7926ffd6f0 Tidy 'routes!' and 'catchers!' proc-macros. 2018-09-16 20:38:02 -07:00
jeb 8e779610c4 Reimplement 'routes!' and 'catchers!' as proc-macros. 2018-09-16 18:52:23 -07:00
Sergio Benitez 46afabdfea Remove neglected and obscure 'Error' type. 2018-09-16 03:07:50 -07:00
Sergio Benitez 351757c6ee Rename 'Rocket::catch()' to 'Rocket::register()'. 2018-09-16 02:25:12 -07:00
Sergio Benitez 112e700836 Reimplement 'catch' attribute as a proc-macro. 2018-09-16 01:32:40 -07:00
jeb 242b358e37 Fix typo in 'handle_error' docstring. 2018-09-11 15:13:20 -07:00
jeb 1da506ea5d Remove use of the 'const_fn' feature. 2018-09-03 19:41:31 -07:00
Sergio Benitez fd6d577158 Remove 'use_extern_macros' feature: stabilized. 2018-08-18 17:06:28 -07:00
Sergio Benitez 7b4747ff1c Fix 'Segments::into_path_buf()' docstring. 2018-08-17 11:14:45 -07:00
Sergio Benitez fe9fad339e Clean up connection pooling documentation. 2018-08-15 23:31:49 -07:00
Eric Dattore 60b9f06407 Implement connection pooling support in contrib.
Resolves #167.
2018-08-15 22:11:53 -07:00
Sergio Benitez 01a5011b61 Add a module-level docstring to 'http'. 2018-08-15 19:55:34 -07:00
Sergio Benitez 10f267a56d Add 'ConfigError::Missing' to identify missing config keys. 2018-08-14 10:31:54 -07:00
Sergio Benitez e0961e0750 Require all 'AdHoc' fairings to be named. 2018-08-14 09:14:06 -07:00
messense 589743579a Fix benchmark compilation. 2018-08-13 15:51:42 -07:00
Sergio Benitez 651c202060 Move 'SegmentError' into 'uri' module. 2018-08-13 02:14:16 -07:00
Sergio Benitez 948a9e6720 Move 'Request::local_cache()' method for nicer docs. 2018-08-13 02:14:16 -07:00
Sergio Benitez 7abfaafcf9 Emit a helpful error when 'LocalRequest' is malformed. 2018-08-13 02:14:16 -07:00
Sergio Benitez 4010a967a6 Allow any 'T: Into<Vec<Route>>' to be mounted. 2018-08-13 02:14:12 -07:00
Sergio Benitez 29c9cffdbe Implement dynamic request handling via 'Handler' trait. 2018-08-12 02:13:42 -07:00
Sean Stangl 9bf585496c Apply more Clippy suggestions. 2018-08-11 23:41:35 -07:00
Ryan 995603666f Force close only the read end of connections.
Previously, when a request's body data exceeded the expected length,
Rocket would shutdown both ends of the corresponding connection. This PR
changes the behavior so that only the read end of the connection, on
Rocket's side, is shutdown. This allows a response to be sent in the
future while still preventing DoS attacks due to exuberant data.

Fixes #386.
2018-08-11 23:10:13 -07:00
Sergio Benitez 83cead775f Fix 'Error' associated type for 'Result<T, T::Error>'. 2018-08-10 19:14:39 -07:00
Sergio Benitez fe59a7fe38 Use better types for 'Error' associated types. 2018-08-10 04:42:30 -07:00
kryptan d9bfc9b104 Implement 'Responder' for '&[u8]'. 2018-08-07 23:58:54 -07:00
Sergio Benitez 41f0614b14 Update request-local state documentation. 2018-08-07 23:16:16 -07:00
jeb d1cfdbaa8e Add documentation and examples for request-local state.
Closes #654.
2018-08-07 19:40:30 -07:00
Marc Mettke cd776d5b6a Add 'and_then', 'failure_then', and 'forward_then' methods to 'Outcome'. 2018-08-07 18:55:04 -06:00
Sergio Benitez d7f6d82fe4 Implement 'FromForm[Value]', 'Responder' proc-macro derives.
This completes the migration of custom derives to proc-macros, removing
the need for the `custom_derive` feature in consumer code. This commit
also includes documentation, unit tests, and compile UI tests for each
of the derives.

Additionally, this commit improves the existing `FromForm` and
`FromFormValue` derives. The generated code for `FromForm` now returns
an error value indicating the error condition. The `FromFormValue`
derive now accepts a `form` attribute on variants for specifying the
exact value string to match against.

Closes #590.
Closes #670.
2018-08-06 19:58:07 -07:00
Sergio Benitez b0f86dcba0 Fix URI normalization checks in 'Rocket::mount()'. 2018-07-29 18:40:24 -07:00
Sergio Benitez 56c6a96f6a Overhaul URI types.
This is fairly large commit with several entangled logical changes.

The primary change in this commit is to completely overhaul how URI
handling in Rocket works. Prior to this commit, the `Uri` type acted as
an origin API. Its parser was minimal and lenient, allowing URIs that
were invalid according to RFC 7230. By contrast, the new `Uri` type
brings with it a strict RFC 7230 compliant parser. The `Uri` type now
represents any kind of valid URI, not simply `Origin` types. Three new
URI types were introduced:

  * `Origin` - represents valid origin URIs
  * `Absolute` - represents valid absolute URIs
  * `Authority` - represents valid authority URIs

The `Origin` type replaces `Uri` in many cases:

  * As fields and method inputs of `Route`
  * The `&Uri` request guard is now `&Origin`
  * The `uri!` macro produces an `Origin` instead of a `Uri`

The strict nature of URI parsing cascaded into the following changes:

  * Several `Route` methods now `panic!` on invalid URIs
  * The `Rocket::mount()` method is (correctly) stricter with URIs
  * The `Redirect` constructors take a `TryInto<Uri>` type
  * Dispatching of a `LocalRequest` correctly validates URIs

Overall, URIs are now properly and uniformly handled throughout Rocket's
codebase, resulting in a more reliable and correct system.

In addition to these URI changes, the following changes are also part of
this commit:

  * The `LocalRequest::cloned_dispatch()` method was removed in favor of
    chaining `.clone().dispatch()`.
  * The entire Rocket codebase uses `crate` instead of `pub(crate)` as a
    visibility modifier.
  * Rocket uses the `crate_visibility_modifier` and `try_from` features.

A note on unsafety: this commit introduces many uses of `unsafe` in the
URI parser. All of these uses are a result of unsafely transforming byte
slices (`&[u8]` or similar) into strings (`&str`). The parser ensures
that these casts are safe, but of course, we must label their use
`unsafe`. The parser was written to be as generic and efficient as
possible and thus can parse directly from byte sources. Rocket, however,
does not make use of this fact and so would be able to remove all uses
of `unsafe` by parsing from an existing `&str`. This should be
considered in the future.

Fixes #443.
Resolves #263.
2018-07-29 00:17:33 -07:00
Sean Stangl a7cc5542ab Fix various clippy warnings in core and codegen. 2018-07-25 15:28:35 -07:00
Sergio Benitez aaad4f5c57 Remove use of 'unsafe' in 'Fairings'. 2018-07-22 22:00:20 -07:00
jeb 0c80217289 Fix various spelling and grammar issues in core and contrib. 2018-07-20 22:14:58 -06:00