Commit Graph

500 Commits

Author SHA1 Message Date
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 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 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
Follpvosten 189fd65b17 Add 'Request::local_cache_async' for use in async request guards. 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 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
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 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
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 1f0577bfc5 Update remaining examples for async. 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 094146b929 Update 'fairings' example for async. 2020-07-11 09:24:28 -07:00
Jeb Rosen bc404f1f6d Use 'body_string_wait' in all example tests. 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
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
gcarq 86d0bdddb2 Replace manual ASCII checks with 'std::char' calls. 2020-06-22 05:07:14 -07:00
Sergio Benitez e1a3d2b6e8 Fix minor formatting issues in 'todo' example. 2020-06-08 12:18:34 -07:00
Sergio Benitez a4f5be93ef Clean up todo example. 2020-06-08 12:12:02 -07:00
Cedric Hutchings da34b66eb4 Use 'Result's instead of 'bool's in todo example. 2020-06-08 12:11:41 -07:00
Ning Sun bbad427079 Update 'handlebars' to 3.0. 2020-06-08 11:41:01 -07:00
Giles Cope ff4b63c0be Add field renaming to query params example. 2020-03-24 16:21:43 -07: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
Paolo Barbolini cd5f96ae15 Update 'uuid', 'unicode-xid', and 'base64' dependencies. 2019-11-30 09:33:14 -08:00
Jeb Rosen e04bceb81e Call iter() instead of into_iter() on arrays (rust-lang/rust#66145). 2019-11-28 12:41:26 -08: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 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 22da02fa64 Remove double semicolons; silence test warnings. 2019-09-09 16:57:03 -07:00
Pieter Frenssen 1383671090 Do not display 'Error:' on a successful logout in the 'session' example. 2019-08-12 17:39:52 -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
Jeb Rosen 2f458b5217 Remove dependence on 'decl_macro' in codegen.
The generated 'uri' helper macros are now re-exports of 'macro_rules'
macros, made possible by the stable 'uniform_paths' feature.
2019-07-19 11:38:35 -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 7f2c9f426c Fix tests for Windows. 2019-07-06 00:59:01 -07:00
Sergio Benitez da7e022f99 Add Rust 2015 example. 2019-06-25 11:30:43 -07:00
Jeb Rosen d9f989a496 Migrate all examples to Rust 2018. 2019-06-25 11:30:43 -07:00
Sergio Benitez 8434a98d5c Set Content-Type on 'MsgPack' responses.
Fixes #1009.
2019-05-23 17:18:17 -07:00
Sergio Benitez 23f5ebcc4f Update 'parking_lot' to 0.8 in 'todo' example. 2019-05-16 13:50:54 -07:00
Sergio Benitez 868a7e6425 Update 'crossbeam' to 0.7 in 'managed_queue' example. 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
jeb b9c3a5c64b Remove test bootstrapping. 2019-02-08 16:50:14 -08:00
Sergio Benitez fbcb99669e Update deprecated 'trim_right()' to 'trim_end()'. 2019-02-06 19:39:44 -08:00
Sergio Benitez 76c830a467 Update 'base64', 'crossbeam', 'rand' dependencies. 2018-11-18 03:47:12 -08:00
Linus Unnebäck 53758c6dd7 Introduce the 'private-cookies' feature. 2018-11-08 23:38:18 -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 983ee9b32d Make inner 'LenientForm' field public. Add 'State::from()'. 2018-11-03 01:52:19 -07:00
jeb 328bf4b32e Support 'uri' macro in 2018 edition crates. 2018-10-30 02:44:22 -07:00
Sergio Benitez 26db5ecb4e Fix normalization and Windows issues. 2018-10-24 00:01:56 -07:00
Sergio Benitez 0b2ece2f65 Update rusqlite dependencies. 2018-10-15 00:28:25 -07:00
Sergio Benitez f857f81d9c Import 'database' attribute with 'macro_use'. 2018-10-09 04:31:09 -07:00
Sergio Benitez 9cb031a47d Modularize contrib. 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 d011cd63fc Remove unnecessary 'use rocket::catch'. 2018-09-16 20:52:07 -07:00
Sergio Benitez d2abbe72e0 Merge 'use's in 'hello_2018' example. 2018-09-16 20:38:10 -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 30cf75335b Embed the diesel database migrations in the `todo` example.
`diesel_cli` is no longer needed for running the example or its tests.
2018-09-11 12:38:10 -07:00
Christophe Courtaut 7b050ebaae Update 'uuid' dependency to '0.7'. 2018-09-11 11:04:50 -07:00
jeb 1da506ea5d Remove use of the 'const_fn' feature. 2018-09-03 19:41:31 -07:00
Sergio Benitez cb18954ef2 Use 'StaticFiles' in todo example. 2018-08-24 14:00:36 -07:00
Sergio Benitez fd6d577158 Remove 'use_extern_macros' feature: stabilized. 2018-08-18 17:06:28 -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 e0961e0750 Require all 'AdHoc' fairings to be named. 2018-08-14 09:14:06 -07:00
Sergio Benitez ec130f96ee Implement a 'StaticFiles' custom handler in contrib.
Closes #239.
2018-08-13 02:17:50 -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
Sergio Benitez fe59a7fe38 Use better types for 'Error' associated types. 2018-08-10 04:42:30 -07: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
jeb 1d1d5259ad Fix compatibility warnings and errors in examples. 2018-07-25 09:01:29 -06:00
Sergio Benitez f8c36f5c67 Update 'diesel', 'parking_lot', and 'rand' dependencies in 'todo' example. 2018-07-22 21:59:40 -07:00
Sergio Benitez 9405fc9055 Update 'rand' dependency in 'pastebin' example. 2018-07-22 21:59:40 -07:00
Sergio Benitez 49365d5fdf Update 'handlebars' to 1.0. 2018-07-22 21:59:40 -07:00
Sergio Benitez 351b8f7c37 Small fixes to request-local state cache implementation. 2018-07-07 18:52:03 -07:00
Ville Hakulinen 97c6b3ace8 Implement Request-Local State Cache.
Resolves #654.
2018-07-07 18:41:21 -07:00
Sergio Benitez 94cfba8b49 Tidy up handlebars example. 2018-07-02 14:11:09 -07:00
Ashley Williams f00c68252c Use inheritance in handlebars example. 2018-07-02 13:50:16 -07:00
David Darrell 76bbcb5de8 Always set 'secret_key' in session example.
This commit also removes a previously unused 'Flash' message.
2018-06-28 19:02:39 -07: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 f5cc69ae57 Add file to preserve empty db directory. 2018-05-29 18:55:25 +02:00
Sergio Benitez 59d4f3d3b6 Use diesel_cli <= 1.2. 2018-05-29 18:37:14 +02:00
Sergio Benitez b12058110d Use static path to database file in todo example. 2018-05-29 18:37:14 +02:00
Sergio Benitez d17b392538 Use diesel <= 1.2 while nightly issues persist. 2018-05-29 18:37:14 +02:00
Kyle Clemens 105137a46d Rename 'UUID' to 'Uuid' in 'rocket_contrib'. 2018-04-14 20:07:50 -07:00
Sergio Benitez 9629b40202 Clear flash cookies only after they're inspected.
Resolves #512.
Resolves #466.
2018-04-14 19:53:36 -07:00
Sergio Benitez efc511c6dc Add a 'FromFormValue' derive. Start 'codegen_next' crate.
The 'codegen_next' crate will eventually be renamed 'codegen'. It
contains procedural macros written with the upcoming 'proc_macro' APIs,
which will eventually be stabilized. All compiler extensions in the
present 'codegen' crate will be rewritten as procedural macros and moved
to the 'codegen_next' crate.

At present, macros from 'codegen_next' are exported from the core
`rocket` crate automatically. In the future, we may wish to feature-gate
this export to allow using Rocket's core without codegen.

Resolves #16.
2018-04-12 16:07:37 -07:00
Sergio Benitez 5b4a35d508 Update codegen for 2018-04-06 nightly. 2018-04-07 13:51:57 -07:00
Sergio Benitez 362f0ccdac Allow shorthand for route format specifiers. 2018-03-22 04:02:37 -05:00
Sergio Benitez 794dc66e3b Remove unnecessary 'dotenv' dependency in 'todo' example. 2018-02-25 20:20:06 -08:00
Sergio Benitez d4e590af83 Fix 'diesel' version in state guide and todo example. 2018-02-21 16:07:09 -08:00
Eric Dattore c48905f483 Use 'diesel::r2d2' in state guide and todo example.
Diesel now reexports r2d2, so rather than including that library
explicitly, let's leverage the reexport.
2018-02-21 15:53:02 -08:00
Sergio Benitez b76a1ef8b9 Update 'uuid' dependency to '0.6'.
Resolves #565.
2018-02-21 00:57:39 -08:00
Sergio Benitez c620411d92 Add 'keep_alive' configuration parameter.
The 'keep_alive' configuration parameter allows HTTP keep-alive timeouts
to be configured or for keep-alive to be disabled entirely.
2018-02-17 04:06:05 -08:00
Sergio Benitez de8e1978c5 Remove unsafe 'from_utf8_unchecked'; improve form parsing.
The 'FormItems' iterator now successfully parses empty keys and values
as well as keys without values.
2018-02-14 14:05:26 -08:00
Donald Robertson 19f59b1f9b Use port 8000 as default for all environments.
Closes #317.
2018-01-20 09:43:19 -08:00
Sergio Benitez f04dc195bd Update 'rusqlite' to fix dependency resolution. 2018-01-19 10:29:51 -08:00
Sergio Benitez 65baa83fb4 Update dependencies.
* 'memchr' to 2.0
  * 'base64' to 0.9
  * 'smallvec' to 0.6
  * 'lazy_static' to 1.0

Update example dependencies.

  * 'rand' to 0.4
  * 'parking_lot' to 0.5
2018-01-05 02:00:26 -08:00
Sergio Benitez 24b2818f8c Update diesel to 1.0. 2018-01-03 01:38:11 -08:00
calhilcaw 401bedebb2 Update docs and examples for diesel 1.0.0-rc1. 2018-01-03 01:38:05 -08:00
Sergio Benitez 9f9971f4cf Tidy up handlebars example. 2017-12-28 20:52:03 -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 bbad1a11ec Use 'into()' in handlebars templates tests. 2017-11-17 12:25:33 -08:00
Sergio Benitez 0d2585051d Fixup Tera templates example for master. 2017-11-17 12:23:51 -08:00
lerina 7bda1b527b Added Tera templates example. 2017-11-17 12:07:53 -08:00
Sergio Benitez 07d4d23cc8 Update dependencies. 2017-10-09 20:15:18 -07:00
Sergio Benitez 237c673be4 Rename '#[error]' to '#[catch]', 'errors!' to 'catchers!'. 2017-09-22 19:04:14 -07:00
Sergio Benitez 32eeae1733 Use 'Uri' instead of 'String' in 'Redirect'. 2017-09-15 04:00:50 -07:00
Sergio Benitez 084481a84e Initial implementation of typed URIs.
This is a breaking change. All Rocket applications using code
generation must now additionally declare usage of the 'decl_macro'
feature.
2017-09-14 22:10:25 -07:00
Lucas Kolstad 2d72928ba1 Properly handle paths with spaces in shell scripts. 2017-09-07 17:07:31 -07:00
Sergio Benitez 237370533c Update cert in 'tls' example for new 'rustls'.
The latest version of `rustls` acts on the SNI extension to TLS without
the apparent ability to disable the behavior. `rustls` requires that the
server's certificate match the client's requested server. The matching
is done by looking at DNS names in the `subjectAltName` extension and
checking if the requested server name is present. Since the certificate
in the `tls` example did not have the `subjectAltName` extension, this
check always failed, and the TLS connection was aborted. This commit
adds the extension to the certificate with a DNS name of `localhost`,
ensuring that TLS succeeds on `localhost`.
2017-09-01 03:16:36 -07:00
Sergio Benitez 3ed0201c6e Remove unused 'extern crate's. 2017-08-31 17:03:47 -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 8183f63630 Remove lints and associated code from 'rocket_codegen'.
Rust's linting API is incredibly unstable, resulting in unnecessary
breakage to `rocket_codegen`. Rocket's lints are also not as
conservative as would be desired, resulting in spurious warnings. For
these reasons, this commit removes linting from `rocket_codegen`.

These lints will likely be reintroduced as part of a 'rocket_lints'
crate. Factoring the lints out to a separate crate means that lint
breakage can be dealt with by uncommenting the dependency instead of
waiting for a new release or backtracking nightlies. In the same vein,
it will likely improve stability of the 'rocket_codegen' crate.
2017-08-15 11:39:22 -07:00
Rolf Sievers 3a76fe03db Improve commentary on collisions in pastebin example. 2017-08-13 02:56:23 -07:00
Katrina Brock 527051d136 Improve bootstrapping instructions in todo example. 2017-08-13 02:50:28 -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 05944c01af Update diesel example dependency to 0.14. 2017-07-06 02:04:00 -07:00
Sergio Benitez 05a8a93eec Add tests for the 'session' example.
Closes #316.
2017-07-04 14:51:41 -07:00
Sergio Benitez 8eb1fff93f Silence incorrect unmanaged state warnings. 2017-07-03 15:37:24 -07:00
Sergio Benitez 150aef7764 Impl 'try' for 'Outcome'. Document 'Cookies'.
The 'try' impl for 'Outcome' allows the '?' operator to be used with
'Outcome' values. This is likely to make 'FromRequest' and 'FromData'
implementations more ergonomic.

This commit also expands the 'IntoOutcome' trait. It is now
implemented for 'Option'. It also now includes an additional
'or_forward' method.
2017-06-24 02:49:31 -07:00
Sergio Benitez cdf9ff9bde Remove 'LoggingLevel' from root. Add ConfigError::Io.
This tentatively completes the 'config' rustdocs.
2017-06-18 21:06:41 -07:00
Sergio Benitez ea485e52e8 Update diesel and rusqlite example dependencies. 2017-06-11 02:57:41 -07:00
Sergio Benitez b8ba7b855f Remove Session in favor of private cookies. New testing API.
Sessions
--------

This commit removes the `Session` type in favor of methods on the
`Cookies` types that allow for adding, removing, and getting private
(signed and encrypted) cookies. These methods provide a superset of
the functionality of `Session` while also being a minimal addition to
the existing API. They can be used to implement the previous `Session`
type as well as other forms of session storage. The new methods are:

  * Cookie::add_private(&mut self, Cookie)
  * Cookie::remove_private(&mut self, Cookie)
  * Cookie::get_private(&self, &str)

Resolves #20

Testing
-------

This commit removes the `rocket::testing` module. It adds the
`rocket::local` module which provides a `Client` type for local
dispatching of requests against a `Rocket` instance. This `local`
package subsumes the previous `testing` package.

Rocket Examples
---------------

The `forms`, `optional_result`, and `hello_alt_methods` examples have
been removed. The following example have been renamed:

  * extended_validation -> form_validation
  * hello_ranks -> ranking
  * from_request -> request_guard
  * hello_tls -> tls

Other Changes
-------------

This commit also includes the following smaller changes:

  * Config::{development, staging, production} constructors have been
    added for easier creation of default `Config` structures.
  * The `Config` type is exported from the root.
  * `Request` implements `Clone` and `Debug`.
  * `Request::new` is no longer exported.
  * A `Response::body_bytes` method was added to easily retrieve a
    response's body as a `Vec<u8>`.
2017-06-08 17:34:50 -07:00
Sergio Benitez 3eeae77ed6 Add tests for 'form_kitchen_sink' example.
Closes #62.
2017-06-02 18:46:34 -07:00
Sergio Benitez 6f4c8b1377 Don't create two DB pools in todo example. 2017-06-01 23:03:08 -07:00
Sergio Benitez f1ec552ac5 Make todo example bootstrapping more resilient. 2017-06-01 22:10:05 -07:00
Sergio Benitez 6a9421935e Add 'Request::route' method to get active 'Route'.
This commit also adds the `base` field to `Route` which allows the
base mount point to be retrieved. Finally, this commits adds an
implementation of `FromRequest` for `Route` which returns the active
route if one is available or forwards otherwise.

This commit is a breaking change: it makes `Request` and `MockRequest`
invariant over the lifetime `'r`. While this shouldn't affect most
applications, it may affect some.

Resolves #108.
2017-05-29 18:00:33 -07:00
Sergio Benitez 83002d3203 Don't assume there is an existing DB. 2017-05-26 17:12:57 -07:00
Sergio Benitez 614ec1359e Add tests for 'todo' example. 2017-05-26 16:52:17 -07:00
Sergio Benitez 6a7903a220 Add tests for 'raw_upload' example. 2017-05-24 22:56:57 -07:00
Sergio Benitez 732cb26eb5 Add tests for 'stream' example. 2017-05-24 22:45:03 -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
Sergio Benitez 28a1ef0916 Fairings, v3.
Modifying the `Rocket` structure just before launch doesn't make sense for
several reasons: 1) those affects can't influence the launch, and 2) they won't
be observed in tests. Thus, an `Attach` fairing kind was added that ameliorates
these issues.
2017-05-17 01:39:36 -07:00
Sergio Benitez 9c9740f966 Fairings v2. 2017-05-14 21:46:01 -07:00
Anton Pirker 781477fff1 Rename 'session_key' config parameter to 'secret_key'.
Resolves #220.
2017-05-12 17:24:25 -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 1e5a1b8940 Remove 'testing' feature. Close stream on network error.
This is a breaking change.

The `testing` feature no longer exists. Testing structures can now be
accessed without any features enabled.

Prior to this change, Rocket would panic when draining from a network
stream failed. With this change, Rocket force closes the stream on any
error.

This change also ensures that the `Fairings` launch output only prints
if at least one fairing has been attached.
2017-04-20 20:36:12 -07:00
Sergio Benitez ac0c78a0cd Initial implementation of fairings: structured middleware for Rocket.
Closes #55.
2017-04-20 13:44:19 -07:00
Sergio Benitez d6e86be1b0 Make route collisions a hard error.
This is a breaking change. Previously, route collisions were warnings.
2017-04-18 17:42:44 -07:00
Sergio Benitez f97b02dda6 Note the extras in the config example. 2017-04-18 17:32:32 -07:00
Sergio Benitez 6dc21e5380 Add support for configurable size limits. 2017-04-18 00:25:13 -07:00
Sergio Benitez 7d2a114280 Set version of managed_queue example to 0.0.0. 2017-04-14 14:58:17 -07:00
Sergio Benitez 8d14cd571c Tidy up managed_queue example. 2017-04-14 14:54:19 -07:00
Stephan Buys b4586f62ee Add managed_queue example and tests. 2017-04-14 14:54:14 -07:00
Sergio Benitez e6615af7e6 Add tests for pastebin example. 2017-04-14 14:39:17 -07:00
Sergio Benitez 3bebdcc53d Add Response::body_string(). Use it in all tests. 2017-04-14 01:59:28 -07:00
Sergio Benitez 0d674c57fd Return `HeaderMap` from Response::headers(). Remove Response::header_values().
This is a breaking change. A call to `Response::headers()` can be
replaced with `Response::headers().iter()`. A call to
`Response::header_values()` can be replaced with
`Response::headers().get()`.
2017-04-14 01:21:06 -07:00
Fabrice Desré da1f6264e4 Enable the "tls" feature in the hello_tls example. 2017-04-13 17:38:56 -07:00
Sergio Benitez 6f29696b4f Make TLS misconfig an error. Always print launch message. 2017-04-13 01:16:09 -07:00
Sergio Benitez 1516ca4fb6 Initial TLS support.
This commit introduces TLS support, provided by `rustls` and a fork of
`hyper-rustls`. TLS support is enabled via the `tls` feature and
activated when the `tls` configuration parameter is set. A new
`hello_tls` example illustrates its usage.

This commit also introduces more robust and complete configuration
settings via environment variables. In particular, quoted string,
array, and table (dictionaries) based configuration parameters can now
be set via environment variables.

Resolves #28.
2017-04-13 00:18:31 -07:00
Sergio Benitez cf47daa8e1 Return 404 on missing static file in todo example. 2017-04-12 02:58:45 -07:00
Sergio Benitez 7c19bf784d Allow form field renaming via #[form(field = "name")] attribute. 2017-04-03 19:06:30 -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 301257623c Update diesel and rusqlite example dependencies. 2017-03-30 02:02:09 -07:00
Sergio Benitez c58ca894b7 Initial implementation of content negotiation via `Accept`.
This is a breaking change.

This commit changes the meaning of the `format` route attribute when
used on non-payload carrying requests (GET, HEAD, CONNECT, TRACE, and
OPTIONS) so that it matches against the preferred media type in the
`Accept` header of the request. The preferred media type is computed
according to the HTTP 1.1 RFC, barring a few specificty rules to come.
2017-03-29 04:08:53 -07:00
Sergio Benitez 9160483554 A route with unspecified query parameters accepts any.
This is a breaking change. It modifies collisions with respect to query
parameters as well as the default ranking of routes.

A route that does not specify query parameters will now match against
requests with _and without_ query parameters, assuming all other
elements of the route match as well. A route that _does_ specify query
parameters will only match requests with query parameters; this remains
true.

To accommodate this change in the most natural manner possible, the
default rankings of routes have changed as illustrated below:

  |-------------+-------+----------+---------------|
  | static path | query | new rank | previous rank |
  |-------------+-------+----------+---------------|
  | yes         | yes   | -4       | 0             |
  | yes         | no    | -3       | 0             |
  | no          | yes   | -2       | 1             |
  | no          | no    | -1       | 1             |
  |-------------+-------+----------+---------------|

In other words, the most specific routes, with preference for paths over
queries, are ranked highest (lower number).
2017-03-27 03:52:26 -07:00
Sergio Benitez 65da988962 Return a `LaunchError` from `launch` when launching fails.
This is a (minor) breaking change. If `rocket.launch()` is the last expression
in a function, the return type will change from `()` to `LaunchError`. A simple
workaround that preserves the previous functionality is to simply add a
semicolon after `launch()`: `rocket.launch();`.

resolves #34
2017-03-15 22:10:09 -07:00
Sergio Benitez 7139941e04 Ensure no files have trailing whitespace. 2017-03-15 19:26:15 -07:00
Sergio Benitez 5434f467a9 Check msgpack example version to 0.0.0. 2017-03-08 17:56:08 -08:00
Sergio Benitez ca2bde6386 Slight cleanup of manual_routes example. 2017-03-08 15:22:36 -08:00
aStoate 1683102e74 Add tests for manual_routes example. 2017-03-08 15:18:49 -08:00
Josh Holmer d43678c35e Add MsgPack implementation to contrib. 2017-03-08 15:12:00 -08:00
Sergio Benitez 393225cedf Use ansi_term::Color, not Colour. 2017-03-08 15:08:13 -08:00
Sergio Benitez a4f532da09 Set examplem versions to 0.0.0. 2017-03-08 14:29:24 -08:00
Sergio Benitez 63e89b04b4 Rename Session::add to Session::set.
Also set a default expiration of 3 hours for session cookies.
2017-03-08 14:25:58 -08:00
Sergio Benitez 16cb7297ab Initial session support.
This commit includes the following additions:
  * A `session` example was added.
  * `Config::take_session_key` was removed.
  * If a `session_key` is not supplied, one is automatically generated.
  * The `Session` type implements signed, encrypted sessions.
  * A `Session` can be retrieved via its request guard.
2017-03-08 03:28:12 -08:00
Sergio Benitez 722ee93f8b Update to cookie 0.7. Use 256-bit session_keys.
This commit involves several breaking changes:
  * `session_key` config param must be a 256-bit base64 encoded string.
  * `FromRequest` is implemented for `Cookies`, not `Cookie`.
  * Only a single `Cookies` instance can be retrieved at a time.
  * `Config::take_session_key` returns a `Vec<u8>`.
  * `Into<Header>` is implemented for `&Cookie`, not `Cookie`.
2017-03-07 01:19:06 -08:00
mikejiang f0836e22fa Add tests for static_files example. 2017-02-24 18:54:13 -08:00
mikejiang 7e7c31b9e7 Add tests for extended_validation example. 2017-02-17 23:35:29 -08:00
Josh Holmer 937fe50ad7 Fix typo in json example. 2017-02-16 19:09:16 -08:00
Sergio Benitez 0acfea9c71 Remove unnecessary pub qualifier in forms example. 2017-02-16 18:30:44 -08:00
Crazy-Owl 3e063af965 Use managed state in json example. 2017-02-16 18:11:03 -08:00
Sergio Benitez 53390164cd Remove the unnecessary hidden field in kitchen sink example. 2017-02-03 18:56:05 -08:00
Sergio Benitez a88aa21b60 Commit the missing db.rs file. 2017-02-02 18:15:24 -08:00
Sergio Benitez a15002877d Use connection pool in todo example. 2017-02-02 18:01:00 -08:00
Sergio Benitez 7f9ced7db3 Add raw sqlite example; not in workspace due to sqlite3-sys conflict. 2017-02-02 18:00:30 -08:00
Sergio Benitez 9069f91bea Remove extraneous argument from popd in todo boostrap. 2017-02-02 15:19:23 -08:00
Sergio Benitez b69527c392 Reenable the options decorator. 2017-02-02 15:02:32 -08:00
Sergio Benitez ecc62beeac Update uuid in contrib to 0.4. 2017-02-02 14:51:04 -08:00
Sergio Benitez 1a18c73970 Update to todo example to diesel 0.10. 2017-02-02 14:47:53 -08:00
Sergio Benitez a9c3b8a919 Silence warnings during testing. 2017-02-02 02:16:21 -08:00
Sergio Benitez 7b8d104ae0 Silence cargo and diesel in todo bootstrap. 2017-02-02 01:08:43 -08:00