Commit Graph

496 Commits

Author SHA1 Message Date
Jeb Rosen 9d4fea2937 Remove 'mongodb' integration from 'contrib'.
The latest version of 'mongodb' is async and implements its own internal
connection pooling.
2020-07-21 10:54:07 -07:00
Jeb Rosen 3a40d1071c Remove 'rusted_cypher' integration from 'contrib'. 2020-07-21 10:54:07 -07:00
Jeb Rosen 62113abcd2 Upgrade 'redis' to 0.15 in 'contrib'. 2020-07-21 10:54:07 -07:00
Jeb Rosen fbe6c1081f Upgrade 'rusqlite' to 0.23 in 'contrib'. 2020-07-21 10:54:07 -07:00
Jeb Rosen 2879f44148 Upgrade 'mysql' to 18.0 in 'contrib'. 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 3f2b8f6006 Remove 'proc_macro' features. 2020-07-16 05:46:39 -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
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 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 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 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 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 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
Jeb Rosen 3796673740 Update UI tests for latest nightly. 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 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
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 6321797a74 Update compile error tests for databases. 2020-07-11 09:24:29 -07:00
Jeb Rosen 0ab787e216 Use 'tokio_executor::blocking' when acquiring connections from synchronous database pools to avoid tying up the executor. 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 76ef92a2e1 Use a tokio timer instead of std:🧵:sleep in template reload test. 2020-07-11 09:24:28 -07:00
Jeb Rosen facc00454c Re-enable the entire test suite:
* Disable compression tests
* Finish migrating all other examples and tests
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 e44c5896b8 Remove stabilized 'async_await' feature gate and update the minimum nightly version. 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 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
Jeb Rosen 633e495a6b Update many doc tests in 'core' for async. 2020-07-11 09:24:28 -07:00
Redrield 5e578e9c3b Upgrade 'msgpack' for async in contrib and examples. 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
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
Ning Sun bbad427079 Update 'handlebars' to 3.0. 2020-06-08 11:41:01 -07:00
Jeb Rosen c19365dcbe Make 'notify' an optional dependency.
It is now required only when the 'templates' feature is active.
2020-06-07 04:02:35 -07:00
Lionel G b38753eaf8 Add 'X-DNS-Prefetch-Control' header to helmet.
Co-authored-by: Sergio Benitez <sb@sergio.bz>
2020-06-04 17:54:28 -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
Sergio Benitez 6a1e4c668c Improve docs for 'Options::NormalizeDirs'. 2020-05-30 01:40:44 -07:00
Sergio Benitez c3187bfe91 Add 'Options::NormalizeDirs' to 'StaticFiles'.
Closes #1198.

Co-authored-by: Keith Wansbrough <keithw@lochan.org>
2020-05-29 17:49:37 -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
Sergio Benitez ee1a9903b6 Update UI tests for latest nightly. 2020-02-15 03:51:56 -08:00
Jeb Rosen 31712018bb Update versions and links for updated dependencies. 2020-01-20 14:51:00 -08:00
Jeb Rosen 4151cd46db Remove [target.'cfg(debug_assertions)'.dependencies] in contrib Cargo.toml.
This is not supported and is the same as putting the contents in
[dependencies] anyway. It became a warning in rust-lang/cargo#7660.
2020-01-19 12:45:08 -08:00
Razican f4bb8bb511 Update depedencies:
* contrib: 'rmp-serde', 'tera', 'memcache', 'mysql', 'postgres', 'redis'.
* examples: 'parking-lot', 'rand'
2020-01-19 11:01:11 -08:00
Jeb Rosen ff2000293c Update 'compiletest' and fix and re-enable compile UI tests. 2020-01-15 17:09:57 -08:00
Paolo Barbolini cd5f96ae15 Update 'uuid', 'unicode-xid', and 'base64' dependencies. 2019-11-30 09:33:14 -08:00
Jeb Rosen 343f51d550 Disable UI tests for now. 2019-11-29 11:18:26 -08:00
Jeb Rosen 22442313a7 Extend 'Engines' example to illustrate its proper use. 2019-11-16 13:15:47 -08:00
adrian5 3a1f012b56 Fix typo in databases documentation: extraneous word 'database'. 2019-11-03 10:06:45 -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
Sergio Benitez 777d01fa87 Remove unused features in contrib codegen. 2019-09-18 19:34:03 -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
Sergio Benitez 0b059e06e5 Update 'devise' to 0.3.
This transitively updates 'syn', 'proc-macro2', and 'quote' to 1.0.
2019-09-05 15:44:25 -07:00
Jacob Pratt 2dd09f90be Remove unused 'doc_cfg' feature. 2019-08-06 14:01:35 -07:00
Sergio Benitez b8ab9e5b23 Add template engine versions to docs. 2019-07-19 13:35:29 -07:00
Ning Sun 93c979eb43 Update 'handlebars' to 2.0. 2019-07-19 13:34:38 -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
Sergio Benitez 7f2c9f426c Fix tests for Windows. 2019-07-06 00:59:01 -07:00
Sergio Benitez 1f9020d26f Fix link to 'Rustqlite' in databases docs. 2019-06-28 17:38:08 -07:00
Jeb Rosen fc78eaf836 Document contrib database library versions.
This commit also adds a note to the contrib database documentation
describing how to enable features in upstream database crates.
2019-06-26 09:11:27 -04:00
Jeb Rosen 2315171971 Migrate contrib to Rust 2018. 2019-06-25 11:30:39 -07:00
Sergio Benitez e458df094f Update 'version_check' to 0.9. 2019-05-24 01:48:42 -07:00
Sergio Benitez 8434a98d5c Set Content-Type on 'MsgPack' responses.
Fixes #1009.
2019-05-23 17:18:17 -07:00
Sergio Benitez 1e611ff86e Set 'StaticFiles' rank with method, not bit-flags. 2019-05-17 10:25:55 -07:00
Sergio Benitez dbcb0a75b9 Allow setting a custom rank on 'StaticFiles'.
Resolves #965.
2019-05-16 16:54:35 -07:00
Sergio Benitez 59d8cfab7f Update 'glob' dependency to 0.3. 2019-05-16 13:50:54 -07:00
Sergio Benitez 5334f17ea9 Enable 'compression' test dependencies conditionally. 2019-05-16 13:50:54 -07:00
Jeb Rosen 273c7a607d Update 'mysql' to 16.0, 'redis' to 0.10. 2019-05-16 13:50:54 -07:00
Leonora Tindall c6c0b3a6e1 Update 'rusqlite' dependency to 0.16. 2019-05-16 13:50:54 -07:00
Adam fd05f998ab Implement 'FromIterator' for 'JsonValue'. 2019-05-14 22:25:49 -07:00
Sergio Benitez 1caf87eb21 Move to 0.5.0-dev on master. 2019-05-13 16:18:48 -07:00
Unknown aa154be51d Fix missing '```' at end of template example code. 2019-05-04 09:07:10 -07:00
Jeb Rosen 0666e425fe Add a few missing pieces of 'compression' documentation. 2019-05-04 08:38:11 -07:00
Jeb Rosen 0a3960b031 Clean up 'compression' module and documentation. 2019-04-27 08:54:21 -07:00
Martin1887 6a55aa7253 Add 'compression' contrib module. 2019-04-27 08:42:00 -07:00
Blake Smith fcd64342fd Fix typo in 'databases' documentation: 'pg_db' -> 'my_db'. 2019-03-13 06:32:28 -07:00
Peter Farr 622f4f399c Flesh out database examples in the API documentation:
* Demonstrate multiple databases in ROCKET_DATABASES environment variable.
  * Add a second example of connection guard type creation.
2019-03-13 06:30:31 -07:00
Sergio Benitez d8ada552c9 Remove duplicate 'use' in 'helmet' tests. 2019-02-06 19:40:26 -08:00
jeb 90296dde80 Change `rocket_contrib` to not depend on default features from `rocket`. 2019-01-31 20:25:44 -08:00
An Long 5ce43ed4e9 Add support for memcache connection pooling in 'rocket_contrib'. 2019-01-13 11:16:11 -08:00
Austin Hartzheim a88bc95201 Specify 'rocket_contrib' version correctly in doc examples. 2019-01-12 14:54:22 -08:00
Eric Dattore aba3ad327b Add database pool integration tests. 2018-12-23 21:12:44 -08:00
Sergio Benitez 3f58ea692f Add compile tests to contrib codegen. 2018-12-23 21:08:07 -08:00
Eric Dattore 7dd0c8fd02 Implement 'DerefMut' for database pools.
This commit also fixes database pool codegen amidst of generics.

Fixes #854.
Resolves #862.
2018-12-23 21:06:45 -08:00
Sergio Benitez 746023fe1f Use '&*' in database docs for reliable deref coercions.
Resolves #855.
2018-12-10 22:20:34 -08:00
Sergio Benitez b88a2d7d05 Add notes about enabling features to contrib docs. 2018-12-07 09:07:27 -08:00
Sergio Benitez a4dcb0cf4c New version: 0.4.0. 2018-12-06 09:19:11 -08:00
Eric Dattore 50a635ed8e Add support for MongoDB connection pooling in 'rocket_contrib'. 2018-12-06 08:17:12 -08:00
Sergio Benitez 90a6749313 New version: 0.4.0-rc.2. 2018-11-30 21:00:18 -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
jeb d14c3393a0 Fix notify dependency version. 2018-11-19 02:29:41 -08: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
jeb af84f60bb8 Fix forced HSTS logic in 'SpaceHelmet'. 2018-11-17 23:51:54 -08:00
Sergio Benitez 3b6c4d2a5f Prefix codegen imports to avoid name collisions.
Fixes #817.
2018-11-12 13:08:39 -08:00
Sergio Benitez 1bb23b8115 Rename 'space_helmet' to 'helmet'. Rework API. 2018-11-08 20:35:30 -08:00
Tal c5167f1150 Add 'space_helmet' contrib module. 2018-11-08 20:35:26 -08:00
Sergio Benitez 4dbd87a36f New version: 0.4.0-rc.1. 2018-10-31 14:35:30 -07:00
Sergio Benitez ef3e7ca2c6 Make all top-level crates publishable. 2018-10-31 03:57:37 -07:00
Sergio Benitez 4ef179cc59 Migrate from 'derive_utils' to published 'devise'.
Resolves #800.
2018-10-29 04:58:56 -07:00
jeb d5fec97fcb Update 'contains_template' documentation. 2018-10-28 22:10:43 -07:00
Sergio Benitez 5c40d3b7e2 Reenable MySQL pooling support. 2018-10-27 18:14:17 -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 e0973d95f1 Log I/O error when live template reloading fails. 2018-10-23 23:58:12 -07:00
Sergio Benitez 21932cc277 Temporarily disable MySQL pooling support.
See rust-lang/rust#55219.
2018-10-21 20:04:17 -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 0b2ece2f65 Update rusqlite dependencies. 2018-10-15 00:28:25 -07:00
Sergio Benitez 8741e678f8 Document contrib modules. 2018-10-12 18:52:38 -07:00
Sergio Benitez f857f81d9c Import 'database' attribute with 'macro_use'. 2018-10-09 04:31:09 -07:00
Sergio Benitez 8b1e93192e Version documentation. 2018-10-09 04:31:09 -07:00
Sergio Benitez 9cb031a47d Modularize contrib. 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 b9bf1ee37d Fix typed URI generation for query reform. 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 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 74007815a0 Replace 'SerdeError' with 'JsonError' in 'Json' data guard.
The new 'JsonError' type allows users to inspect the raw string that
failed to parse as a given JSON value.

Resolves #772.
2018-09-18 18:57:11 -07:00
jeb 95cbc241db Ensure 'ContextManager' is 'Sync' on all platforms. 2018-09-16 23:39:32 -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 112e700836 Reimplement 'catch' attribute as a proc-macro. 2018-09-16 01:32:40 -07:00
Sergio Benitez 1f2f38ea5f Update to latest 'derive_utils'. 2018-09-14 23:15:58 -07:00
Christophe Courtaut 7b050ebaae Update 'uuid' dependency to '0.7'. 2018-09-11 11:04:50 -07:00
Sébastien Santoro bac186fc0d Fix typo in contrib 'Cargo.toml'. 2018-09-03 19:54:02 -07:00
Sergio Benitez fd6d577158 Remove 'use_extern_macros' feature: stabilized. 2018-08-18 17:06:28 -07:00
Sergio Benitez 58519e495e Test all contrib features individually. 2018-08-18 16:52:45 -07:00
Sergio Benitez 9966a07c58 Update 'redis' to '0.9'.
Closes #743.
2018-08-18 16:50:55 -07:00
EloD10 46da03c3c3 Fix typo in 'DatabaseConfig' docstring. 2018-08-17 11:19:37 -07:00
Sergio Benitez a62248f7ce Consistently use 'diesel_postgres_pool' feature. 2018-08-17 11:16:36 -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 429c0dfeb6 Fix template fairing given 'ConfigError::Missing'. 2018-08-15 19:00:43 -07:00
Sergio Benitez 55459db773 Properly constrain 'serde_json' version. 2018-08-14 11:20:42 -07:00
Sergio Benitez d699827079 Reexport new 'serde_json::json_internal_vec' macro. 2018-08-14 09:53:04 -07:00
Sergio Benitez ec130f96ee Implement a 'StaticFiles' custom handler in contrib.
Closes #239.
2018-08-13 02:17:50 -07:00
Sergio Benitez 4098ddd92f Improve templates contrib test by reusing code. 2018-08-13 02:14:16 -07:00
Sean Stangl 9bf585496c Apply more Clippy suggestions. 2018-08-11 23:41:35 -07:00
Sergio Benitez 0612c644ad Fix typo in 'Template::finalize()' docstring. 2018-08-11 23:17:22 -07:00
Sergio Benitez f941b1310b Improve template engine customization docs. 2018-08-10 23:29:12 -07:00
jeb 491b04cf5a Implement template auto-reload.
Resolves #163.
2018-08-10 23:29:12 -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
Sergio Benitez 49365d5fdf Update 'handlebars' to 1.0. 2018-07-22 21:59:40 -07:00
jeb 0c80217289 Fix various spelling and grammar issues in core and contrib. 2018-07-20 22:14:58 -06:00
Sergio Benitez 5acb08a026 Make contrib MsgPack tests actually run. 2018-07-10 17:08:58 -07:00
Sergio Benitez 0045486227 Implement Serialize + Deserialize for contrib JsonValue. 2018-07-10 17:08:26 -07:00
Sergio Benitez 39c952f8eb Clean up 'TemplateMetadata' implementation. 2018-07-10 17:07:53 -07:00
Marc Mettke c381386098 Add 'TemplateMetadata' request guard to contrib.
The request guard allows a user to query information about loaded
templates. In particular, a user can check whether a template was
loaded.
2018-07-10 15:11:43 -07:00
Beatriz Rizental 965c90afc9 Add 'log = off' config option to disable all logging. 2018-07-07 18:12:25 -07:00
Sergio Benitez 88d3b59c71 Use 'or_else' to tidy up 'Template::show()'. 2018-07-02 19:14:17 -07:00
Sergio Benitez 397a646dcf Fix conditional compilation for contrib templates tests. 2018-06-03 20:42:15 +02:00
Sergio Benitez 1e8e4cc553 Fix Cargo.toml path to README. 2018-06-03 19:39:32 +02:00
Sergio Benitez f171dc9d09 Reorganize repository.
The directory structure has changed to better isolate crates serving
core and contrib. The new directory structure is:

  contrib/
    lib/ - the contrib library
  core/
    lib/ - the core Rocket library
    codegen/ - the "compile extension" codegen library
    codegen_next/ - the new proc-macro library
  examples/ - unchanged
  scripts/ - unchanged
  site/ - unchanged

This commit also removes the following files:

  appveyor.yml - AppVeyor (Rust on Windows) is far too spotty for use
  rustfmt.toml - rustfmt is, unfortunately, not mature enough for use

Finally, all example Cargo crates were marked with 'publish = false'.
2018-06-03 18:44:38 +02:00
Sergio Benitez a040ddd122 Fix links to configuration guide. 2018-05-13 23:33:42 -07:00
Marshall Bowers b876f233a8 Replace 'macro_reexport' with 'pub use'. 2018-05-04 23:36:09 -07:00
Kyle Clemens 105137a46d Rename 'UUID' to 'Uuid' in 'rocket_contrib'. 2018-04-14 20:07:50 -07:00
messense fa217082fd Preallocate 512 byte buffer for JSON deserialization. 2018-04-08 17:25:35 -07:00
Sergio Benitez 9dcb285799 Remove stabilized feature gates.
These are:

  * i128_type
  * conservative_impl_trait
  * never_type
2018-04-03 21:52:33 -07:00
Sergio Benitez 8e46530a39 Update 'handlebars' to 0.32. 2018-02-25 20:12:53 -08:00
Sergio Benitez b76a1ef8b9 Update 'uuid' dependency to '0.6'.
Resolves #565.
2018-02-21 00:57:39 -08:00
messense ae8e9025d2 Eagerly read JSON data for deserialization.
Issue #547 identified a performance issue when serde's 'from_reader' is
used to deserialize incoming data. Using 'from_str' resolves the issue.
This commit swaps a use of 'from_reader' in favor of 'from_str' in
rocket_contrib's 'Json' implementation.

Additionally, this commit ensures that un-deserialized JSON data is
discarded as long as it is within the JSON data limit.

Closes #562.
2018-02-19 02:58:37 -08:00
Sergio Benitez 3a8d0e8a9a Dynamically increase/decrease log level at launch.
This commit modifies the internal logger so that launch messages are
emitted with the proper "info" level. The approach is to temporarily
weaken the log level to "normal" during launch and reset it to the
user's setting after launching.

This commit also upgrades to 'log' 0.4.

Fixes #553.
2018-01-29 13:16:04 -08:00
Sergio Benitez f2331a831a Update handlebars to 0.30, tera to 0.11. 2018-01-23 18:53:55 -08:00
Sergio Benitez f7e5c105ee Improve documentation on accessing templating engines. 2017-12-28 22:57:49 -08:00
Jeb Rosen f9f1ed75cd Have 'Template::show()' take an '&Rocket'.
This completes the effort started in #431, allowing for direct
customization of the underlying templating engines of 'Template'.

Resolves #64. Closes #234. Closes #431. Closes #500.
2017-12-28 19:57:13 -08:00
Ning Sun d79cb9d8f0 Add 'Template::custom()' to customize templating engines. 2017-12-28 19:49:55 -08:00
Sergio Benitez aad97e6be0 Use correct rustdoc 'html_root_url'.
Fixes #474.
2017-11-22 10:58:20 -08:00
Sergio Benitez f87b46d6c5 Fix incorrect emission of config errors from templates. 2017-11-17 12:24:33 -08:00
Sergio Benitez 16feedd563 Remove 'drop_types_in_const' feature: stabilized. 2017-09-14 22:39:19 -07:00
Sergio Benitez 2f84d4b18a Add 'Config::root_relative()'. Make TLS config paths root-relative.
Prior to this commit, relative paths to TLS PEM files were incorrectly
treated as being relative to the CWD as opposed to the Rocket config
file, when present. This commit resolves the issue.
2017-09-04 19:01:26 -07:00
Sergio Benitez 3ed0201c6e Remove unused 'extern crate's. 2017-08-31 17:03:47 -07:00
Sergio Benitez 7ce250b82f Update dependencies for ring 0.12. 2017-08-31 16:58:24 -07:00
Sergio Benitez a019f0d1f3 Use new 'JsonValue' type as return type of 'json!'.
Prior to this commit, a 'json!' invocation returned a value of type
'Value' from 'serde_json'. Because 'Value' does not implement
'Responder', most uses of 'json!' were wrapped in 'Json':
'Json(json!(..))`. By returning a crate-local 'JsonValue' type that
implements 'Responder', this repetition is resolved, and a 'json!' can
appear unwrapped.

This commit also removes the reexport of 'Value' from 'rocket_contrib'
as well as the default type of 'Value' for 'T' in 'Json<T>'.
2017-08-25 23:14:42 -07:00
Sergio Benitez 3f6c6fd576 Move to 0.4.0-dev on master. 2017-08-11 09:32:27 -07:00
Sergio Benitez 944eaa3e3c Emit all error messages from Tera on init failure.
Resolves #369.
2017-08-02 16:58:55 -07:00
Laurentiu Nicola 5f0583eb04 Don't skip over the first Tera error.
The first line in the Tera error messages is sometimes less useful,
but in other cases, like when the context is not a map or struct,
contains the complete description. As such, always include it, even if
the output is slightly uglier. Also don't append periods at the end
since some Tera messages already have them.
2017-07-26 23:32:35 -04:00
Sergio Benitez cdacda0896 New version: 0.3.0. 2017-07-14 11:30:48 -07:00
Sergio Benitez 897313730d Use TitleCase for all 'content::' struct names. 2017-07-12 15:21:45 -07:00
Sergio Benitez 65886c8c4e Rename 'contrib::JSON' to 'contrib::Json'. 2017-07-12 15:11:41 -07:00
Sergio Benitez 6050eb5169 Update for 2017-07-09. 'associated_consts' is stable. 2017-07-09 22:00:01 -07:00
Sergio Benitez b0612d7346 Enable features on docs.rs. 2017-06-30 02:41:00 -07:00
Sergio Benitez 539a7fc55b Remove 'struct_field_attributes' feature: it's been stabilized. 2017-06-19 17:44:01 -07:00
Sergio Benitez 6a7fde6d70 Initial cleanup of 'http' docs. Add 'handler::Outcome' docs.
This commit also changes the signature of the 'ContentType'
'from_extension" method so that it returns an 'Option<ContentType>' as
opposed to 'ContentType'.

This commit also disallows negative quality values in 'Accept' media
types.
2017-06-19 17:32:33 -07:00
Sergio Benitez 43a4028085 Use a less confusing version number during dev. 2017-06-18 02:25:26 -07:00
Sergio Benitez 876a8b8329 Make tera/handlebars rendering a little clearer. 2017-06-16 20:56:51 -07:00
Sergio Benitez 2bfb41d968 Update 'handlebars' and 'base64' dependencies. 2017-06-11 01:07:18 -07:00
Sergio Benitez 9a297f776b Tidy up broken links. Set 'html_root_url'. 2017-06-11 01:03:59 -07:00
Sergio Benitez 73fed03ef4 New version: 0.2.8. 2017-06-01 22:10:05 -07:00
Sergio Benitez 5f2b2ee3df New version: 0.2.7. 2017-05-26 20:37:54 -07:00
Sergio Benitez 9b955747e4 Remove config global state. Use Responder::respond_to.
This commit includes two major changes to core:

  1. Configuration state is no longer global. The `config::active()`
     function has been removed. The active configuration can be
     retrieved via the `config` method on a `Rocket` instance.

  2. The `Responder` trait has changed. `Responder::respond(self)` has
     been removed in favor of `Responder::respond_to(self, &Request)`.
     This allows responders to dynamically adjust their response based
     on the incoming request.

Additionally, it includes the following changes to core and codegen:

  * The `Request::guard` method was added to allow for simple
    retrivial of request guards.
  * The `Request::limits` method was added to retrieve configured
    limits.
  * The `File` `Responder` implementation now uses a fixed size body
    instead of a chunked body.
  * The `Outcome::of<R: Responder>(R)` method was removed while
    `Outcome::from<R: Responder(&Request, R)` was added.
  * The unmounted and unmanaged limits are more cautious: they will only
    emit warnings when the `Rocket` receiver is known.

This commit includes one major change to contrib:

  1. To use contrib's templating, the fairing returned by
     `Template::fairing()` must be attached to the running Rocket
     instance.

Additionally, the `Display` implementation of `Template` was removed. To
directly render a template to a `String`, the new `Template::show`
method can be used.
2017-05-19 03:29:08 -07:00
Lance Carlson 13061e9062 Update uuid dependency to 0.5. 2017-05-05 12:20:36 -07:00
Sergio Benitez 30fac32978 Upgrade dependencies to Serde 1.0.
Closes #272.
Resolves #273.
2017-04-24 17:37:18 -07:00
Sergio Benitez 7b48ca7103 Add optional input for IntoOutcome. Add mapper methods to Outcome.
This is a breaking change to `IntoOutcome`.

The MsgPack and JSON types now use `into_outcome` to generate the final
`Outcome` from their `FromData` implementations.

Resolves #98.
2017-04-18 21:56:21 -07:00
Roman Frołow 8555a0fad5 Fix typo in Template documentation: words -> works. 2017-04-18 19:52:18 -07:00
Sergio Benitez 1524b9a6b2 Document size limits. 2017-04-18 00:36:39 -07:00
Sergio Benitez 6dc21e5380 Add support for configurable size limits. 2017-04-18 00:25:13 -07:00
Sergio Benitez e6bbeacb1c New version: 0.2.6. 2017-04-17 16:21:56 -07:00
Sergio Benitez 9b7f58448a New version: 0.2.5. 2017-04-16 14:29:04 -07:00
Sergio Benitez f5ec470a7d Use the `RawStr` type for raw parameter strings.
This is a breaking change.

The `&str` type no longer implements `FromParam`. The `&RawStr` type
should be used in its place.
2017-03-31 00:18:58 -07:00
Sergio Benitez 0c44e44641 Use the `RawStr` type for all form raw strings.
This is a breaking change.

This commit introduces `RawStr` to forms. In particular, after this
commit, the `&str` type no longer implements `FromFormValue`, and so it
cannot be used as a field in forms. Instad, the `&RawStr` can be used.

The `FormItems` iterator now returns an `(&RawStr, &RawStr)` pair.
2017-03-30 23:06:53 -07:00
Sergio Benitez f57d984e2e New version: 0.2.4. 2017-03-30 19:56:12 -07:00
Sergio Benitez 13359d4f50 Reformulate ContentType as a wrapper around MediaType. 2017-03-23 22:41:42 -07:00
Sergio Benitez 605e8fdc0e Update Tera to 0.8. 2017-03-23 15:28:49 -07:00
Sergio Benitez 09550b6e7c New version: 0.2.3. 2017-03-22 19:47:52 -07:00
Ryan Leckey 5086f0eb01 Default generic T in `JSON` to `Value`. 2017-03-08 17:53:05 -08:00
Sergio Benitez fc89d0e96c Move {json,msgpack}/mod.rs to top-level contrib/src. 2017-03-08 15:17:37 -08:00
Josh Holmer d43678c35e Add MsgPack implementation to contrib. 2017-03-08 15:12:00 -08:00
Sergio Benitez 6be902162d New version: 0.2.2. 2017-02-26 18:31:15 -08:00
Sergio Benitez d99de8e05b New version: 0.2.1. 2017-02-24 13:57:33 -08:00
Sergio Benitez 46403b8d0a Iterate through Tera error chain for better errors. 2017-02-17 00:23:41 -08:00
Sergio Benitez 6184d94619 Expose docstring for JSON Responder impl. 2017-02-16 18:06:09 -08:00
Sergio Benitez a496d1dbc4 Fix typos in JSON docs. 2017-02-09 00:18:47 -08:00
Sergio Benitez c7db553286 New version: 0.2.0. 2017-02-06 05:35:19 -08:00
Sergio Benitez 266c62fb22 Implement FromFormValue for contrib UUID. 2017-02-03 17:09:22 -08:00
Sergio Benitez aefa2f1494 Use pub(crate) to enforce doc(hidden). 2017-02-03 02:17:06 -08:00
Sergio Benitez 84abac7f2b Unignore template test. Upstream fix landed. 2017-02-02 18:48:34 -08:00
Sergio Benitez 2b65be32e0 Ignore render example due to broken upstream crate. 2017-02-02 15:39:30 -08:00
Sergio Benitez 5dff45086a Update to tera 0.7. 2017-02-02 15:18:23 -08:00
Sergio Benitez ecc62beeac Update uuid in contrib to 0.4. 2017-02-02 14:51:04 -08:00
Sergio Benitez cc22836867 Precisely route formats. Make 'content_type' an 'Option' in 'Request'.
This commit changes the routing algorithm. In particular, it enforces
precise matching of formats. With this change, a route with a specified
format only matches requests that have the same format specified. A
route with no format specified matches any request's format. This is
contrast to the previous behavior, where a route without a specified
format would match requests regardless of their format or whether one
was specified.

This commit also changes the following:
  * The return type of the 'content_type' method of 'Request' is now
    'Option<ContentType>'.
  * The 'ContentType' request guard forwards when the request has no
    specified ContentType.
  * The 'add_header' and 'replace_header' methods take the header
    argument generically.

Closes #120.
2017-02-01 03:12:24 -08:00
Sergio Benitez 5fabb43a1b Update to serde 0.9, handlebars 0.25. Move from `map!` to `json!` macro.
Resolves #154.
2017-01-31 17:15:42 -08:00
Sergio Benitez 5f04beaafc Use pegged Tera. 2017-01-28 21:52:36 -08:00
Sergio Benitez 8fd19cce4f Use upstream Tera. Emit warning on conflicting templates. 2017-01-26 12:47:20 -08:00
Sergio Benitez c61e740572 Allow any Serialize type in RHS of map macro. 2017-01-26 11:56:06 -08:00
Sergio Benitez 0a0b64b9b6 New version: 0.1.6. 2017-01-26 11:26:50 -08:00
Sergio Benitez b164da1a01 Rename JSON::unwrap() to JSON::into_inner(). 2017-01-15 03:00:46 -08:00
Sergio Benitez 08278e8f0e New version: 0.1.5. 2017-01-14 08:45:03 -08:00
Sergio Benitez 77ae330212 Minor style changes to UUID contrib. 2017-01-14 08:20:15 -08:00
Lori Holden 8f39d3399e Add UUID type to contrib. 2017-01-14 08:08:01 -08:00
Sergio Benitez 6fd0503cea Expose SerdeError. 2017-01-12 23:07:01 -08:00
Sergio Benitez 3c07cf96df Overhaul templating contrib library: use `register` callback.
This commit improves and changes the templating library in the following ways:

  * Templates are now registered/loaded at initialization.
  * No synchronization is required to read templates.
  * All templates are properly loaded (fixes #122).
  * Tera templates are given the proper name: `index`, not `index.html.tera`.
  * Rendering tests added for both templating engines.

There is one breaking change:

  * Tera templates are given the proper name: `index`, not `index.html.tera`.
2017-01-12 02:52:23 -08:00
Sergio Benitez 5db5e9f688 Update handlebars to 0.24. 2017-01-10 15:06:00 -08:00