Commit Graph

262 Commits

Author SHA1 Message Date
Sergio Benitez b642e94a2c Reduce or consolidate git-based dependencies. 2018-08-15 19:44:35 -07:00
Sergio Benitez 651c202060 Move 'SegmentError' into 'uri' module. 2018-08-13 02:14:16 -07:00
Sergio Benitez fe59a7fe38 Use better types for 'Error' associated types. 2018-08-10 04:42:30 -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
Sean Stangl a7cc5542ab Fix various clippy warnings in core and codegen. 2018-07-25 15:28:35 -07:00
Sergio Benitez e25a82b14b Update dependencies for ring 0.13. 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 19d8569cdb Update core, codegen for 2018-07-16 nightly. 2018-07-17 14:06:32 -07:00
Sergio Benitez 18a91c938e Reexport 'cookie::SameSite' from the http module. 2018-07-10 17:09:24 -07:00
Imron Alston a383d49ab0 Add FLAC (audio/flac) as a known media type. 2018-06-28 19:42:59 -07:00
Sergio Benitez 64bbed1422 Improve documentation on unsafe usage.
All uses of `unsafe` are now thoroughly documented with arguments and
informal proofs of correctness as well as conditions that must hold for
these arguments to pass.

This commit also reduces the number of `unsafe` uses by 7, bringing the
count to ~10 non-test uses of `unsafe`.
2018-06-20 14:02:12 +02:00
Sergio Benitez df7111143e Split the 'http' module into its own 'rocket_http' crate. 2018-06-07 15:34:47 +02:00