2016-03-28 09:34:09 +00:00
|
|
|
#![feature(specialization)]
|
2018-10-05 04:44:42 +00:00
|
|
|
#![feature(decl_macro)]
|
2017-06-24 09:49:16 +00:00
|
|
|
#![feature(try_trait)]
|
2018-04-22 08:44:43 +00:00
|
|
|
#![feature(fnbox)]
|
2018-04-29 01:23:14 +00:00
|
|
|
#![feature(never_type)]
|
2018-10-06 04:56:46 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
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)]
|
|
|
|
#![feature(try_from)]
|
2018-09-26 08:13:57 +00:00
|
|
|
#![feature(label_break_value)]
|
2017-03-21 09:04:07 +00:00
|
|
|
|
2018-06-04 16:06:08 +00:00
|
|
|
#![recursion_limit="256"]
|
2016-03-19 02:05:29 +00:00
|
|
|
|
2018-10-07 04:16:02 +00:00
|
|
|
#![doc(html_root_url = "https://api.rocket.rs/0.4.0-dev")]
|
2018-10-06 13:25:17 +00:00
|
|
|
#![doc(html_favicon_url = "https://rocket.rs/favicon.ico")]
|
|
|
|
#![doc(html_logo_url = "https://rocket.rs/images/logo-boxed.png")]
|
2017-06-11 08:03:59 +00:00
|
|
|
|
2016-10-03 00:52:04 +00:00
|
|
|
//! # Rocket - Core API Documentation
|
2016-09-30 04:44:27 +00:00
|
|
|
//!
|
|
|
|
//! Hello, and welcome to the core Rocket API documentation!
|
|
|
|
//!
|
|
|
|
//! This API documentation is highly technical and is purely a reference.
|
2018-10-06 13:25:17 +00:00
|
|
|
//! There's an [overview] of Rocket on the main site as well as a [full,
|
|
|
|
//! detailed guide]. If you'd like pointers on getting started, see the
|
|
|
|
//! [quickstart] or [getting started] chapters of the guide.
|
2016-09-30 04:44:27 +00:00
|
|
|
//!
|
2018-10-07 04:16:02 +00:00
|
|
|
//! You may also be interested in looking at the
|
|
|
|
//! [`rocket_contrib`](../rocket_contrib) documentation, which contains
|
|
|
|
//! automatic JSON (de)serialiazation, templating support, static file serving,
|
|
|
|
//! and other useful features.
|
2018-10-06 13:25:17 +00:00
|
|
|
//!
|
|
|
|
//! [overview]: https://rocket.rs/overview
|
|
|
|
//! [full, detailed guide]: https://rocket.rs/guide
|
|
|
|
//! [quickstart]: https://rocket.rs/guide/quickstart
|
|
|
|
//! [getting started]: https://rocket.rs/guide/getting-started
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
|
|
|
//! ## Libraries
|
|
|
|
//!
|
2018-10-05 04:44:42 +00:00
|
|
|
//! Rocket's functionality is split into two crates:
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
2018-10-06 13:25:17 +00:00
|
|
|
//! 1. Core - This core library. Needed by every Rocket application.
|
2018-10-07 04:16:02 +00:00
|
|
|
//! 2. [Contrib](../rocket_contrib) - Provides useful functionality for many
|
2017-02-03 09:15:01 +00:00
|
|
|
//! Rocket applications. Completely optional.
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
|
|
|
//! ## Usage
|
|
|
|
//!
|
2018-10-06 13:25:17 +00:00
|
|
|
//! First, depend on `rocket` in `Cargo.toml`:
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
2018-10-06 13:25:17 +00:00
|
|
|
//! ```toml
|
2016-10-03 00:52:04 +00:00
|
|
|
//! [dependencies]
|
2018-10-06 13:25:17 +00:00
|
|
|
//! rocket = "0.4.0-dev"
|
2016-10-03 00:52:04 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
2016-12-20 00:51:59 +00:00
|
|
|
//! Then, add the following to the top of your `main.rs` file:
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
2016-10-18 02:29:58 +00:00
|
|
|
//! ```rust
|
2018-10-06 04:56:46 +00:00
|
|
|
//! #![feature(proc_macro_hygiene, decl_macro)]
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
2018-09-20 04:14:30 +00:00
|
|
|
//! #[macro_use] extern crate rocket;
|
2018-10-06 13:25:17 +00:00
|
|
|
//! # #[get("/")] fn hello() { }
|
2018-09-20 04:14:30 +00:00
|
|
|
//! # fn main() { rocket::ignite().mount("/", routes![hello]); }
|
2016-10-03 00:52:04 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
2016-10-21 09:56:57 +00:00
|
|
|
//! See the [guide](https://rocket.rs/guide) for more information on how to
|
2016-10-18 02:29:58 +00:00
|
|
|
//! write Rocket applications. Here's a simple example to get you started:
|
|
|
|
//!
|
|
|
|
//! ```rust
|
2018-10-06 04:56:46 +00:00
|
|
|
//! #![feature(proc_macro_hygiene, decl_macro)]
|
2016-10-18 02:29:58 +00:00
|
|
|
//!
|
2018-06-28 15:55:15 +00:00
|
|
|
//! #[macro_use] extern crate rocket;
|
2016-10-18 02:29:58 +00:00
|
|
|
//!
|
|
|
|
//! #[get("/")]
|
|
|
|
//! fn hello() -> &'static str {
|
|
|
|
//! "Hello, world!"
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! fn main() {
|
|
|
|
//! # if false { // We don't actually want to launch the server in an example.
|
2017-03-16 05:10:09 +00:00
|
|
|
//! rocket::ignite().mount("/", routes![hello]).launch();
|
2016-10-18 02:29:58 +00:00
|
|
|
//! # }
|
|
|
|
//! }
|
|
|
|
//! ```
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
|
|
|
//! ## Configuration
|
|
|
|
//!
|
2017-02-03 09:15:01 +00:00
|
|
|
//! Rocket and Rocket libraries are configured via the `Rocket.toml` file and/or
|
|
|
|
//! `ROCKET_{PARAM}` environment variables. For more information on how to
|
2018-10-06 13:25:17 +00:00
|
|
|
//! configure Rocket, see the [configuration section] of the guide as well as
|
|
|
|
//! the [`config`] module documentation.
|
|
|
|
//!
|
|
|
|
//! [configuration section]: https://rocket.rs/guide/configuration/
|
2016-10-18 02:29:58 +00:00
|
|
|
//!
|
|
|
|
//! ## Testing
|
|
|
|
//!
|
2018-10-06 13:25:17 +00:00
|
|
|
//! The [`local`] module contains structures that facilitate unit and
|
|
|
|
//! integration testing of a Rocket application. The top-level [`local`] module
|
|
|
|
//! documentation and the [testing chapter of the guide] include detailed
|
|
|
|
//! examples.
|
|
|
|
//!
|
|
|
|
//! [testing chapter of the guide]: https://rocket.rs/guide/testing/#testing
|
2016-10-04 00:09:13 +00:00
|
|
|
|
2018-10-22 06:53:09 +00:00
|
|
|
#[allow(unused_imports)] #[macro_use] extern crate rocket_codegen;
|
|
|
|
#[doc(hidden)] pub use rocket_codegen::*;
|
2018-04-12 23:07:37 +00:00
|
|
|
|
2018-06-07 13:34:47 +00:00
|
|
|
extern crate rocket_http;
|
2016-10-04 00:09:13 +00:00
|
|
|
#[macro_use] extern crate log;
|
2017-03-21 09:04:07 +00:00
|
|
|
#[macro_use] extern crate pear;
|
2017-06-02 04:44:31 +00:00
|
|
|
extern crate yansi;
|
2016-10-03 10:39:56 +00:00
|
|
|
extern crate toml;
|
2017-01-12 10:38:14 +00:00
|
|
|
extern crate num_cpus;
|
2017-01-21 03:31:46 +00:00
|
|
|
extern crate state;
|
2017-01-27 07:08:15 +00:00
|
|
|
extern crate time;
|
2017-02-02 00:34:49 +00:00
|
|
|
extern crate memchr;
|
2017-03-07 09:19:06 +00:00
|
|
|
extern crate base64;
|
2017-06-20 01:29:26 +00:00
|
|
|
extern crate isatty;
|
2016-08-24 08:30:09 +00:00
|
|
|
|
2016-10-04 10:54:24 +00:00
|
|
|
#[cfg(test)] #[macro_use] extern crate lazy_static;
|
|
|
|
|
2016-09-30 22:20:11 +00:00
|
|
|
#[doc(hidden)] #[macro_use] pub mod logger;
|
2018-10-23 08:23:11 +00:00
|
|
|
#[doc(hidden)] pub mod ext;
|
2017-06-06 20:41:04 +00:00
|
|
|
pub mod local;
|
2016-08-24 08:30:09 +00:00
|
|
|
pub mod request;
|
|
|
|
pub mod response;
|
2016-10-08 02:27:26 +00:00
|
|
|
pub mod outcome;
|
2016-10-15 01:57:36 +00:00
|
|
|
pub mod config;
|
2016-10-25 11:24:07 +00:00
|
|
|
pub mod data;
|
2016-12-15 08:47:31 +00:00
|
|
|
pub mod handler;
|
2017-04-20 20:43:01 +00:00
|
|
|
pub mod fairing;
|
2017-06-12 22:08:34 +00:00
|
|
|
pub mod error;
|
2016-03-12 18:45:19 +00:00
|
|
|
|
2018-06-07 13:34:47 +00:00
|
|
|
// Reexport of HTTP everything.
|
|
|
|
pub mod http {
|
2018-08-16 02:55:34 +00:00
|
|
|
//! Types that map to concepts in HTTP.
|
|
|
|
//!
|
|
|
|
//! This module exports types that map to HTTP concepts or to the underlying
|
|
|
|
//! HTTP library when needed.
|
|
|
|
|
2018-06-07 13:34:47 +00:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use rocket_http::*;
|
|
|
|
}
|
|
|
|
|
2016-04-01 23:54:53 +00:00
|
|
|
mod router;
|
|
|
|
mod rocket;
|
2016-04-03 10:36:30 +00:00
|
|
|
mod codegen;
|
2016-04-06 10:26:43 +00:00
|
|
|
mod catcher;
|
2016-04-02 07:51:40 +00:00
|
|
|
|
2016-10-08 11:42:22 +00:00
|
|
|
#[doc(inline)] pub use response::Response;
|
2016-09-30 22:20:11 +00:00
|
|
|
#[doc(inline)] pub use handler::{Handler, ErrorHandler};
|
2016-10-08 11:42:22 +00:00
|
|
|
#[doc(hidden)] pub use codegen::{StaticRouteInfo, StaticCatchInfo};
|
2016-10-25 11:39:31 +00:00
|
|
|
#[doc(inline)] pub use outcome::Outcome;
|
2016-10-25 11:27:16 +00:00
|
|
|
#[doc(inline)] pub use data::Data;
|
2017-06-06 20:41:04 +00:00
|
|
|
#[doc(inline)] pub use config::Config;
|
2016-10-04 00:09:13 +00:00
|
|
|
pub use router::Route;
|
2017-01-21 03:31:46 +00:00
|
|
|
pub use request::{Request, State};
|
2016-04-06 10:26:43 +00:00
|
|
|
pub use catcher::Catcher;
|
2016-04-01 23:54:53 +00:00
|
|
|
pub use rocket::Rocket;
|
2016-10-03 10:39:56 +00:00
|
|
|
|
2018-10-06 13:25:17 +00:00
|
|
|
/// Alias to [`Rocket::ignite()`] Creates a new instance of `Rocket`.
|
2016-10-03 10:39:56 +00:00
|
|
|
pub fn ignite() -> Rocket {
|
|
|
|
Rocket::ignite()
|
|
|
|
}
|
2016-11-04 13:35:04 +00:00
|
|
|
|
2018-10-06 13:25:17 +00:00
|
|
|
/// Alias to [`Rocket::custom()`]. Creates a new instance of `Rocket` with a
|
|
|
|
/// custom configuration.
|
2018-07-03 20:47:17 +00:00
|
|
|
pub fn custom(config: config::Config) -> Rocket {
|
|
|
|
Rocket::custom(config)
|
2016-11-04 13:35:04 +00:00
|
|
|
}
|