Commit Graph

328 Commits

Author SHA1 Message Date
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
Jeb Rosen 4bb4c61528 Allow implementations of on_request fairings to return a Future that borrows from self, request, and data. 2020-07-11 09:24:29 -07:00
Jeb Rosen cc3298c3e4 Allow implementations of FromData to return a Future that borrows from the request. 2020-07-11 09:24:29 -07:00
Jeb Rosen 468f4d9314 Simplify FromRequestAsync trait definition. 2020-07-11 09:24:29 -07:00
Paolo Barbolini 003bf77c29 Upgrade to tokio 0.2.0.
* Update 'tokio', 'tokio-rustls', and 'hyper'.
* Remove unused dependencies on some `futures-*` crates.
* Rework 'spawn_on', which is now 'serve'.
* Simplify Ctrl-C handling.
2020-07-11 09:24:29 -07:00
Jeb Rosen 7c4cd068d1 Update for rust-lang/rust#64856.
Raise the nightly version to one that accepts '...(format!(...)).await'.

This additionally reverts commit bdbf80f2da.
2020-07-11 09:24:29 -07:00
Jeb Rosen df52616074 Update error positions after changes for async #[catch] support. 2020-07-11 09:24:29 -07:00
Jeb Rosen 2fa2d636e4 Implement FromRequestAsync instead of FromRequest for Option and Result. 2020-07-11 09:24:29 -07:00
Jeb Rosen 4e5b889358 Add async-routes test for #[get] and #[catch]. 2020-07-11 09:24:29 -07:00
Follpvosten 189fd65b17 Add 'Request::local_cache_async' for use in async request guards. 2020-07-11 09:24:29 -07:00
Jeb Rosen 5317664893 Fix UI tests for FromRequestAsync. 2020-07-11 09:24:29 -07:00
Jeb Rosen 1c28a9413b Allow catchers to be async fn. 2020-07-11 09:24:29 -07:00
Jeb Rosen adf7e4233a Add 'FromRequestAsync' and use it in route codegen.
'FromRequestAsync' is automatically implemented for all types
that implement 'FromRequest'.
2020-07-11 09:24:29 -07:00
Jeb Rosen ea06878581 Update 'hyper', 'futures-*-preview', and 'tokio-*' dependencies.
Use I/O traits and types from 'tokio-io' as much as possible.

A few adapters only exist in futures-io-preview and use
futures-tokio-compat as a bridge for now.
2020-07-11 09:24:29 -07:00
Jeb Rosen 0d89637e8b Propagate errors while writing out response instead of panicking. 2020-07-11 09:24:28 -07:00
Jeb Rosen 8718561bf8 Emit an error when #[async_test] is applied to a function with parameters. 2020-07-11 09:24:28 -07:00
Jeb Rosen d1815e527f Update 'hyper', 'tokio', and 'tokio-rustls'.
* hyper -> 0.13.0-alpha.2
* tokio -> 0.2.0-alpha.5
* tokio-rustls -> 0.12.0-alpha.3
2020-07-11 09:24:28 -07:00
Jeb Rosen af36f299c6 Fix ordering of messages in a UI test. 2020-07-11 09:24:28 -07:00
Jeb Rosen 523c6099fb Replace use of 'hyper::AddrIncoming' with a Listener API and implement TLS.
Types can now implement the new 'Listener' trait, which means they can
report the address they are listening on and asynchronously accept
connections. 'Connection's are read/write streams that can additionally
report the remote address.

Listener is implemented for 'tokio_net::tcp::TcpListener' and for
the new 'rocket_http::tls::TlsListener' based on 'tokio-rustls'.

The new private function 'Rocket::listen_on()' now does the main setup
for launch and is generic over a Listener. In the future, a more refined
version of the API can be exposed so that applications can implement
their own listeners.
2020-07-11 09:24:28 -07:00
Jeb Rosen 62a99e9e49 Fix a minor compilation error, possibly caused by rust-lang/rust#64292. 2020-07-11 09:24:28 -07:00
Jeb Rosen 77a64c73bb Fix some launch error handling in tests and examples. 2020-07-11 09:24:28 -07:00
Jeb Rosen a0d2651e38 Fix a few unused import warnings. 2020-07-11 09:24:28 -07:00
Jacob Pratt cd6a80c230 Implement an API to request a graceful shutdown.
Additionally listen for Ctrl-C as a shutdown signal by default.
2020-07-11 09:24:28 -07:00
Jeb Rosen 0d6e46944b Use tokio's current_thread runtime for async_test to increase performance. 2020-07-11 09:24:28 -07:00
Jacob Pratt c7ecfc69c3 Use 'futures::future::BoxFuture' instead of 'Pin<Box<...>>' for readability. 2020-07-11 09:24:28 -07:00
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 baa2ed27f3 Update UI tests affected by removal of typed headers. 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 63a4ae0485 Silence warnings on 'extern crate proc_macro'. 2020-06-08 12:25:10 -07:00
Sergio Benitez 55d2b2bfb6 Properly mock 'Key::try_generate()'. 2020-06-07 04:02:35 -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 ea9865ec42 Allow multiple versions of 'rustls' and 'ring'.
Co-authored-by: TotalKrill <kristoffer.odmark90@gmail.com>
2020-06-04 18:59:11 -07:00
Sergio Benitez 3c47fa895a Enable minimal set of 'cookie' features. 2020-06-04 18:54:23 -07:00
Jeb Rosen 91fb0804be Hide docs for more generated items. 2020-06-04 18:01:20 -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 578038619f Add 'Origin::map_path()' method. 2020-05-29 17:49:37 -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
Jeb Rosen 3abafaaedb Update UI tests for latest nightly. 2020-04-21 18:12:08 -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 ee1a9903b6 Update UI tests for latest nightly. 2020-02-15 03:51:56 -08:00
Sergio Benitez 385b69cf69 Migrate to 'binascii' for base 16, 64 decoding. 2020-02-14 17:14:37 -08:00
Sergio Benitez 9f0e02fe27 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-02-06 21:16:45 -08:00
Sergio Benitez d0bfd8a3bb Update 'cookie' to 0.13.2. 2020-01-29 14:17:01 -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
Jeb Rosen ff2000293c Update 'compiletest' and fix and re-enable compile UI tests. 2020-01-15 17:09:57 -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 96235615ce Update compile tests for changes in rust nightly. 2019-11-29 11:18:32 -08:00
Jeb Rosen 343f51d550 Disable UI tests for now. 2019-11-29 11:18:26 -08:00
Jeb Rosen e7e84a6d41 Fix and update benchmarks. 2019-11-16 13:08:36 -08:00
Matt Brubeck 8bf6aa2068 Update 'smallvec' to '1.0'. 2019-11-16 13:02:50 -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
Jeb Rosen 335d8f7dbb Adjust '#[catch]' codegen output to fix a UI test regression in latest nightly. 2019-09-21 08:33:16 -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