Commit Graph

79 Commits

Author SHA1 Message Date
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 3eb873d89d Tidy 'uri!' proc-macro. Improve error reporting. 2018-10-04 02:00:04 -07:00
jeb 7624aaf3e4 Reimplement 'uri!' as a proc-macro. 2018-10-03 21:56:37 -07:00
Sergio Benitez cee2f4439f Fix 'content_types' example for debug-only 'FromData' impl. 2018-09-27 01:16:26 -07:00
Sergio Benitez ec4cc3a293 Allow transforms in 'FromData'. Add 'FromDataSimple'.
The new 'FromData' trait allows an implementor to instruct the caller to
maintain state on its stack and later pass a borrow for processing.
Among other things, it greatly simplifies the 'Form' type, removing a
use of unsafe, and allows references in deserialized data guards.
2018-09-26 21:33:02 -07:00
Sergio Benitez 633d37bc97 Fix invalid TOML test for updated 'toml' dependency. 2018-09-25 19:41:59 -07:00
Sergio Benitez 24ee97575b Remove Collider trait. 2018-09-24 19:44:38 -07:00
Sergio Benitez 1a3fd1d237 Add known media types and extensions.
Adds the following to the list of known media types:

  * audio/webm (WEBA)
  * image/tiff (TIFF)
  * audio/aac (AAC)
  * text/calendar (Calendar)
  * video/mpeg (MPEG)
  * application/x-tar (TAR)
  * application/gzip (GZIP)
  * video/quicktime (MOV)
  * video/mp4 (MP4)

Also adds the following to the list of known extensions:

  * .weba (WEBA)
  * .ogv (OGG)
  * .mp4 (MP4)
  * .mpeg4 (MP4)
  * .aac (AAC)
  * .ics (Calendar)
  * .bin (Binary)
  * .mpg (MPEG)
  * .mpeg (MPEG)
  * .tar (TAR)
  * .gz (GZIP)
  * .tif (TIFF)
  * .tiff (TIFF)
  * .mov (MOV)
2018-09-18 18:25:39 -07:00
Sergio Benitez d011cd63fc Remove unnecessary 'use rocket::catch'. 2018-09-16 20:52:07 -07:00
Sergio Benitez 7926ffd6f0 Tidy 'routes!' and 'catchers!' proc-macros. 2018-09-16 20:38:02 -07:00
jeb 8e779610c4 Reimplement 'routes!' and 'catchers!' as proc-macros. 2018-09-16 18:52:23 -07:00
Sergio Benitez 46afabdfea Remove neglected and obscure 'Error' type. 2018-09-16 03:07:50 -07:00
Sergio Benitez 351757c6ee Rename 'Rocket::catch()' to 'Rocket::register()'. 2018-09-16 02:25:12 -07:00
Sergio Benitez 112e700836 Reimplement 'catch' attribute as a proc-macro. 2018-09-16 01:32:40 -07:00
Sergio Benitez 1f2f38ea5f Update to latest 'derive_utils'. 2018-09-14 23:15:58 -07:00
jeb cfdb2a404b Add Icon (image/x-icon) as a known media type. 2018-09-11 15:16:06 -07:00
jeb 242b358e37 Fix typo in 'handle_error' docstring. 2018-09-11 15:13:20 -07:00
Tal 8172f748b3 Implement 'Clone' for all URI types. 2018-09-03 19:42:34 -07:00
jeb 1da506ea5d Remove use of the 'const_fn' feature. 2018-09-03 19:41:31 -07:00
Sergio Benitez 42361c31f1 Use crates.io version of 'compiletest_rs'. 2018-08-26 19:24:13 -07:00
Sergio Benitez df0b96d3fa Remove 'attr_literals' feature: stabilized. 2018-08-26 19:18:49 -07:00
jeb 59e9f7fcc9 Update codegen for 2018-08-23 nightly. 2018-08-24 00:40:56 -06:00
Sergio Benitez fd6d577158 Remove 'use_extern_macros' feature: stabilized. 2018-08-18 17:06:28 -07:00
Sergio Benitez 7b4747ff1c Fix 'Segments::into_path_buf()' docstring. 2018-08-17 11:14:45 -07:00
Sergio Benitez fe9fad339e Clean up connection pooling documentation. 2018-08-15 23:31:49 -07:00
Eric Dattore 60b9f06407 Implement connection pooling support in contrib.
Resolves #167.
2018-08-15 22:11:53 -07:00
Sergio Benitez 01a5011b61 Add a module-level docstring to 'http'. 2018-08-15 19:55:34 -07:00
Sergio Benitez b642e94a2c Reduce or consolidate git-based dependencies. 2018-08-15 19:44:35 -07:00
messense 135b7d29ae Update codegen for 2018-08-14 nightly. 2018-08-14 22:01:33 -07:00
Sergio Benitez 10f267a56d Add 'ConfigError::Missing' to identify missing config keys. 2018-08-14 10:31:54 -07:00
Sergio Benitez e0961e0750 Require all 'AdHoc' fairings to be named. 2018-08-14 09:14:06 -07:00
messense 589743579a Fix benchmark compilation. 2018-08-13 15:51:42 -07:00
Sergio Benitez 651c202060 Move 'SegmentError' into 'uri' module. 2018-08-13 02:14:16 -07:00
Sergio Benitez 948a9e6720 Move 'Request::local_cache()' method for nicer docs. 2018-08-13 02:14:16 -07:00
Sergio Benitez 7abfaafcf9 Emit a helpful error when 'LocalRequest' is malformed. 2018-08-13 02:14:16 -07:00
Sergio Benitez 4010a967a6 Allow any 'T: Into<Vec<Route>>' to be mounted. 2018-08-13 02:14:12 -07:00
Sergio Benitez 29c9cffdbe Implement dynamic request handling via 'Handler' trait. 2018-08-12 02:13:42 -07:00
Sean Stangl 9bf585496c Apply more Clippy suggestions. 2018-08-11 23:41:35 -07:00
Ryan 995603666f Force close only the read end of connections.
Previously, when a request's body data exceeded the expected length,
Rocket would shutdown both ends of the corresponding connection. This PR
changes the behavior so that only the read end of the connection, on
Rocket's side, is shutdown. This allows a response to be sent in the
future while still preventing DoS attacks due to exuberant data.

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #443.
Resolves #263.
2018-07-29 00:17:33 -07:00