Commit Graph

1761 Commits

Author SHA1 Message Date
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 854e90d39f Migrate CI to Github Actions. 2020-07-11 14:59:33 -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
Jeb Rosen 114a733d70 Use 'tokio::fs::File' in the 'pastebin' example. 2020-07-11 10:07:37 -07:00
Jeb Rosen 2b3d8110f1 Use '#[rocket::launch]' in guide examples. 2020-07-11 10:07:37 -07:00
Jeb Rosen 2c82b3e1d5 Update and fix guide tests. 2020-07-11 10:07:37 -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 96bafd8ac5 Mention async testing in the testing guide. 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 85b3259120 Convert assertions in 'form_kitchen_sink' tests to use macros. 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
Jeb Rosen 3796673740 Update UI tests for latest nightly. 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 70db7fb2ea Add some general documentation on async as it pertains to Rocket. 2020-07-11 09:24:29 -07:00
Jeb Rosen f2487ccec5 Update the guide for async-related API changes. 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