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 01:26:15 +00:00
|
|
|
#![feature(crate_visibility_modifier)]
|
2018-07-21 22:11:08 +00:00
|
|
|
#![feature(never_type)]
|
2018-08-18 23:52:45 +00:00
|
|
|
#![feature(doc_cfg)]
|
2017-01-12 10:52:23 +00:00
|
|
|
|
2017-06-11 08:03:59 +00:00
|
|
|
// TODO: Version URLs.
|
2017-11-22 18:58:20 +00:00
|
|
|
#![doc(html_root_url = "https://api.rocket.rs")]
|
2017-06-11 08:03:59 +00:00
|
|
|
|
2016-09-19 23:24:01 +00:00
|
|
|
//! This crate contains officially sanctioned contributor libraries that provide
|
|
|
|
//! functionality commonly used by Rocket applications.
|
|
|
|
//!
|
|
|
|
//! These libraries are always kept in-sync with the core Rocket library. They
|
|
|
|
//! provide common, but not fundamental, abstractions to be used by Rocket
|
|
|
|
//! applications. In particular, contributor libraries typically export types
|
2017-01-10 21:33:30 +00:00
|
|
|
//! implementing a combination of the `FromRequest`, `FromParam`, and
|
|
|
|
//! `Responder` traits.
|
2016-09-19 23:24:01 +00:00
|
|
|
//!
|
|
|
|
//! Each module in this library is held behind a feature flag, with the most
|
|
|
|
//! common modules exposed by default. The present feature list is below, with
|
|
|
|
//! an asterisk next to the features that are enabled by default:
|
|
|
|
//!
|
2017-07-12 22:11:41 +00:00
|
|
|
//! * [json*](struct.Json.html)
|
2018-08-13 09:13:55 +00:00
|
|
|
//! * [static_files*](static_files)
|
2017-02-08 03:40:14 +00:00
|
|
|
//! * [msgpack](struct.MsgPack.html)
|
2016-09-22 11:24:04 +00:00
|
|
|
//! * [handlebars_templates](struct.Template.html)
|
|
|
|
//! * [tera_templates](struct.Template.html)
|
2018-04-14 01:39:34 +00:00
|
|
|
//! * [uuid](struct.Uuid.html)
|
2018-08-15 09:07:17 +00:00
|
|
|
//! * [${database}_pool](databases/index.html)
|
2016-09-19 23:24:01 +00:00
|
|
|
//!
|
|
|
|
//! The recommend way to include features from this crate via Cargo in your
|
|
|
|
//! project is by adding a `[dependencies.rocket_contrib]` section to your
|
|
|
|
//! `Cargo.toml` file, setting `default-features` to false, and specifying
|
|
|
|
//! features manually. For example, to use the JSON module, you would add:
|
|
|
|
//!
|
2016-10-08 02:12:58 +00:00
|
|
|
//! ```toml,ignore
|
2016-09-19 23:24:01 +00:00
|
|
|
//! [dependencies.rocket_contrib]
|
|
|
|
//! version = "*"
|
|
|
|
//! default-features = false
|
|
|
|
//! features = ["json"]
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! This crate is expected to grow with time, bringing in outside crates to be
|
|
|
|
//! officially supported by Rocket.
|
|
|
|
|
|
|
|
#[macro_use] extern crate log;
|
|
|
|
#[macro_use] extern crate rocket;
|
|
|
|
|
2017-02-01 01:15:42 +00:00
|
|
|
#[cfg(feature = "serde")]
|
|
|
|
extern crate serde;
|
|
|
|
|
2016-09-19 23:24:01 +00:00
|
|
|
#[cfg(feature = "json")]
|
2017-02-01 01:15:42 +00:00
|
|
|
extern crate serde_json;
|
|
|
|
|
2018-05-03 03:54:28 +00:00
|
|
|
#[cfg(feature = "json")]
|
2018-08-14 16:53:04 +00:00
|
|
|
pub use serde_json::{json_internal, json_internal_vec};
|
2018-05-03 03:54:28 +00:00
|
|
|
|
2017-09-16 05:34:33 +00:00
|
|
|
#[cfg(feature = "handlebars_templates")]
|
|
|
|
pub extern crate handlebars;
|
|
|
|
|
|
|
|
#[cfg(feature = "tera_templates")]
|
|
|
|
pub extern crate tera;
|
|
|
|
|
2017-02-01 01:15:42 +00:00
|
|
|
#[cfg(feature = "json")]
|
|
|
|
#[cfg_attr(feature = "json", macro_use)]
|
2016-12-29 03:01:16 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub mod json;
|
2016-09-19 23:24:01 +00:00
|
|
|
|
2016-12-29 03:01:16 +00:00
|
|
|
#[cfg(feature = "json")]
|
2018-09-19 01:30:25 +00:00
|
|
|
pub use json::{Json, JsonError, JsonValue};
|
2016-09-22 11:12:07 +00:00
|
|
|
|
2017-02-08 03:40:14 +00:00
|
|
|
#[cfg(feature = "msgpack")]
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub mod msgpack;
|
|
|
|
|
|
|
|
#[cfg(feature = "msgpack")]
|
|
|
|
pub use msgpack::{MsgPack, MsgPackError};
|
|
|
|
|
2017-02-01 01:15:42 +00:00
|
|
|
#[cfg(feature = "templates")]
|
|
|
|
mod templates;
|
2017-01-13 07:07:01 +00:00
|
|
|
|
2016-09-22 11:12:07 +00:00
|
|
|
#[cfg(feature = "templates")]
|
2018-07-09 12:36:40 +00:00
|
|
|
pub use templates::{Engines, Template, TemplateMetadata};
|
2017-01-10 21:33:30 +00:00
|
|
|
|
2017-02-01 01:15:42 +00:00
|
|
|
#[cfg(feature = "uuid")]
|
|
|
|
mod uuid;
|
|
|
|
|
2017-01-10 21:33:30 +00:00
|
|
|
#[cfg(feature = "uuid")]
|
2018-04-14 01:39:34 +00:00
|
|
|
pub use uuid::{Uuid, UuidParseError};
|
2018-08-13 09:13:55 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "static_files")]
|
|
|
|
pub mod static_files;
|
2018-07-21 22:11:08 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "database_pool")]
|
|
|
|
pub mod databases;
|
|
|
|
|
|
|
|
#[cfg(feature = "database_pool_codegen")]
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket_contrib_codegen;
|
|
|
|
|
|
|
|
#[cfg(feature = "database_pool_codegen")]
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub use rocket_contrib_codegen::*;
|