2017-06-06 20:41:04 +00:00
|
|
|
use std::fmt;
|
2019-08-14 18:29:55 +00:00
|
|
|
use std::sync::Arc;
|
2017-06-06 20:41:04 +00:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
use std::ops::{Deref, DerefMut};
|
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
|
|
|
use std::borrow::Cow;
|
2017-06-06 20:41:04 +00:00
|
|
|
|
2019-06-13 01:48:02 +00:00
|
|
|
use crate::{Request, Response, Data};
|
|
|
|
use crate::http::{Status, Method, Header, Cookie, uri::Origin, ext::IntoOwned};
|
|
|
|
use crate::local::Client;
|
2017-06-06 20:41:04 +00:00
|
|
|
|
2017-06-30 09:06:03 +00:00
|
|
|
/// A structure representing a local request as created by [`Client`].
|
|
|
|
///
|
|
|
|
/// # Usage
|
|
|
|
///
|
|
|
|
/// A `LocalRequest` value is constructed via method constructors on [`Client`].
|
|
|
|
/// Headers can be added via the [`header`] builder method and the
|
|
|
|
/// [`add_header`] method. Cookies can be added via the [`cookie`] builder
|
|
|
|
/// method. The remote IP address can be set via the [`remote`] builder method.
|
|
|
|
/// The body of the request can be set via the [`body`] builder method or
|
|
|
|
/// [`set_body`] method.
|
|
|
|
///
|
|
|
|
/// ## Example
|
|
|
|
///
|
|
|
|
/// The following snippet uses the available builder methods to construct a
|
|
|
|
/// `POST` request to `/` with a JSON body:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::{ContentType, Cookie};
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.expect("valid rocket");
|
2017-06-30 09:06:03 +00:00
|
|
|
/// let req = client.post("/")
|
|
|
|
/// .header(ContentType::JSON)
|
|
|
|
/// .remote("127.0.0.1:8000".parse().unwrap())
|
|
|
|
/// .cookie(Cookie::new("name", "value"))
|
|
|
|
/// .body(r#"{ "value": 42 }"#);
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-30 09:06:03 +00:00
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// # Dispatching
|
|
|
|
///
|
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
|
|
|
/// A `LocalRequest` can be dispatched in one of two ways:
|
2017-06-30 09:06:03 +00:00
|
|
|
///
|
|
|
|
/// 1. [`dispatch`]
|
|
|
|
///
|
2017-09-05 16:40:41 +00:00
|
|
|
/// This method should always be preferred. The `LocalRequest` is consumed
|
|
|
|
/// and a response is returned.
|
2017-06-30 09:06:03 +00:00
|
|
|
///
|
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
|
|
|
/// 2. [`mut_dispatch`]
|
2017-06-30 09:06:03 +00:00
|
|
|
///
|
2017-09-05 16:40:41 +00:00
|
|
|
/// This method should _only_ be used when either it is known that the
|
|
|
|
/// application will not modify the request, or it is desired to see
|
|
|
|
/// modifications to the request. No cloning occurs, and the request is not
|
|
|
|
/// consumed.
|
2017-06-30 09:06:03 +00:00
|
|
|
///
|
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
|
|
|
/// Additionally, note that `LocalRequest` implements `Clone`. As such, if the
|
|
|
|
/// same request needs to be dispatched multiple times, the request can first be
|
|
|
|
/// cloned and then dispatched: `request.clone().dispatch()`.
|
|
|
|
///
|
2019-06-13 01:48:02 +00:00
|
|
|
/// [`Client`]: crate::local::Client
|
2017-06-30 09:06:03 +00:00
|
|
|
/// [`header`]: #method.header
|
|
|
|
/// [`add_header`]: #method.add_header
|
|
|
|
/// [`cookie`]: #method.cookie
|
|
|
|
/// [`remote`]: #method.remote
|
|
|
|
/// [`body`]: #method.body
|
|
|
|
/// [`set_body`]: #method.set_body
|
|
|
|
/// [`dispatch`]: #method.dispatch
|
|
|
|
/// [`mut_dispatch`]: #method.mut_dispatch
|
2017-06-06 20:41:04 +00:00
|
|
|
pub struct LocalRequest<'c> {
|
2018-04-15 02:41:37 +00:00
|
|
|
client: &'c Client,
|
2019-08-14 18:29:55 +00:00
|
|
|
// This `Arc` exists so that we can transfer ownership to the `LocalResponse`
|
2018-06-20 12:02:12 +00:00
|
|
|
// selectively on dispatch. This is necessary because responses may point
|
|
|
|
// into the request, and thus the request and all of its data needs to be
|
|
|
|
// alive while the response is accessible.
|
|
|
|
//
|
2019-08-14 18:29:55 +00:00
|
|
|
// Because both a `LocalRequest` and a `LocalResponse` can hold an `Arc` to
|
2018-06-20 12:02:12 +00:00
|
|
|
// the same `Request`, _and_ the `LocalRequest` can mutate the request, we
|
|
|
|
// must ensure that 1) neither `LocalRequest` not `LocalResponse` are `Sync`
|
2018-07-12 03:44:09 +00:00
|
|
|
// or `Send` and 2) mutations carried out in `LocalRequest` are _stable_:
|
2018-06-20 12:02:12 +00:00
|
|
|
// they never _remove_ data, and any reallocations (say, for vectors or
|
|
|
|
// hashmaps) result in object pointers remaining the same. This means that
|
|
|
|
// even if the `Request` is mutated by a `LocalRequest`, those mutations are
|
2018-07-12 03:44:09 +00:00
|
|
|
// not observable by `LocalResponse`.
|
2018-06-20 12:02:12 +00:00
|
|
|
//
|
2019-08-14 18:29:55 +00:00
|
|
|
// The first is ensured by the embedding of the `Arc` type which is neither
|
2018-06-20 12:02:12 +00:00
|
|
|
// `Send` nor `Sync`. The second is more difficult to argue. First, observe
|
|
|
|
// that any methods of `LocalRequest` that _remove_ values from `Request`
|
|
|
|
// only remove _Copy_ values, in particular, `SocketAddr`. Second, the
|
2018-06-24 14:43:31 +00:00
|
|
|
// lifetime of the `Request` object is tied to the lifetime of the
|
2018-06-20 12:02:12 +00:00
|
|
|
// `LocalResponse`, so references from `Request` cannot be dangling in
|
|
|
|
// `Response`. And finally, observe how all of the data stored in `Request`
|
2018-06-24 14:43:31 +00:00
|
|
|
// is converted into its owned counterpart before insertion, ensuring stable
|
2018-06-20 12:02:12 +00:00
|
|
|
// addresses. Together, these properties guarantee the second condition.
|
2019-08-14 18:29:55 +00:00
|
|
|
request: Arc<Request<'c>>,
|
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
|
|
|
data: Vec<u8>,
|
|
|
|
uri: Cow<'c, str>,
|
2017-06-06 20:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c> LocalRequest<'c> {
|
|
|
|
#[inline(always)]
|
2019-09-20 20:43:05 +00:00
|
|
|
pub(crate) fn new(
|
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
|
|
|
client: &'c Client,
|
|
|
|
method: Method,
|
|
|
|
uri: Cow<'c, str>
|
|
|
|
) -> LocalRequest<'c> {
|
|
|
|
// We set a dummy string for now and check the user's URI on dispatch.
|
2020-06-14 15:57:51 +00:00
|
|
|
let request = Request::new(client.manifest(), method, Origin::dummy());
|
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
|
|
|
|
|
|
|
// Set up any cookies we know about.
|
|
|
|
if let Some(ref jar) = client.cookies {
|
2018-11-06 02:59:44 +00:00
|
|
|
let cookies = jar.read().expect("LocalRequest::new() read lock");
|
|
|
|
for cookie in cookies.iter() {
|
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
|
|
|
request.cookies().add_original(cookie.clone().into_owned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See the comments on the structure for what's going on here.
|
2019-08-24 17:27:10 +00:00
|
|
|
let request = Arc::new(request);
|
|
|
|
LocalRequest { client, request, uri, data: vec![] }
|
2017-06-06 20:41:04 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 09:06:03 +00:00
|
|
|
/// Retrieves the inner `Request` as seen by Rocket.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.expect("valid rocket");
|
2017-06-30 09:06:03 +00:00
|
|
|
/// let req = client.get("/");
|
|
|
|
/// let inner_req = req.inner();
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-30 09:06:03 +00:00
|
|
|
/// ```
|
2017-06-06 20:41:04 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn inner(&self) -> &Request<'c> {
|
|
|
|
&*self.request
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
2018-06-20 12:02:12 +00:00
|
|
|
fn request_mut(&mut self) -> &mut Request<'c> {
|
|
|
|
// See the comments in the structure for the argument of correctness.
|
2019-08-24 17:27:10 +00:00
|
|
|
Arc::get_mut(&mut self.request).expect("mutable aliasing!")
|
2018-06-20 12:02:12 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 03:44:09 +00:00
|
|
|
// This method should _never_ be publicly exposed!
|
2018-06-20 12:02:12 +00:00
|
|
|
#[inline(always)]
|
|
|
|
fn long_lived_request<'a>(&mut self) -> &'a mut Request<'c> {
|
|
|
|
// See the comments in the structure for the argument of correctness.
|
|
|
|
// Additionally, the caller must ensure that the owned instance of
|
2019-08-14 18:29:55 +00:00
|
|
|
// `Arc<Request>` remains valid as long as the returned reference can be
|
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
|
|
|
// accessed.
|
2019-08-24 17:27:10 +00:00
|
|
|
unsafe { &mut *(self.request_mut() as *mut _) }
|
2017-06-06 20:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Add a header to this request.
|
|
|
|
///
|
2017-06-30 09:06:03 +00:00
|
|
|
/// Any type that implements `Into<Header>` can be used here. Among others,
|
|
|
|
/// this includes [`ContentType`] and [`Accept`].
|
|
|
|
///
|
2019-06-13 01:48:02 +00:00
|
|
|
/// [`ContentType`]: crate::http::ContentType
|
|
|
|
/// [`Accept`]: crate::http::Accept
|
2017-06-30 09:06:03 +00:00
|
|
|
///
|
2017-06-06 20:41:04 +00:00
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Add the Content-Type header:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::ContentType;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
2017-06-06 20:41:04 +00:00
|
|
|
/// # #[allow(unused_variables)]
|
2020-06-14 15:57:53 +00:00
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
/// let req = client.get("/").header(ContentType::JSON);
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-06 20:41:04 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn header<H: Into<Header<'static>>>(mut self, header: H) -> Self {
|
2018-06-20 12:02:12 +00:00
|
|
|
self.request_mut().add_header(header.into());
|
2017-06-06 20:41:04 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Adds a header to this request without consuming `self`.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Add the Content-Type header:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::ContentType;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
/// let mut req = client.get("/");
|
|
|
|
/// req.add_header(ContentType::JSON);
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-06 20:41:04 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn add_header<H: Into<Header<'static>>>(&mut self, header: H) {
|
2018-06-20 12:02:12 +00:00
|
|
|
self.request_mut().add_header(header.into());
|
2017-06-06 20:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the remote address of this request.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Set the remote address to "8.8.8.8:80":
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
/// let address = "8.8.8.8:80".parse().unwrap();
|
|
|
|
/// let req = client.get("/").remote(address);
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-06 20:41:04 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn remote(mut self, address: SocketAddr) -> Self {
|
2018-06-20 12:02:12 +00:00
|
|
|
self.request_mut().set_remote(address);
|
2017-06-06 20:41:04 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add a cookie to this request.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Add `user_id` cookie:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::Cookie;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
/// # #[allow(unused_variables)]
|
|
|
|
/// let req = client.get("/")
|
|
|
|
/// .cookie(Cookie::new("username", "sb"))
|
2017-06-30 09:06:03 +00:00
|
|
|
/// .cookie(Cookie::new("user_id", "12"));
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-06 20:41:04 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
2019-06-13 01:48:02 +00:00
|
|
|
pub fn cookie(self, cookie: Cookie<'_>) -> Self {
|
2018-04-15 02:41:37 +00:00
|
|
|
self.request.cookies().add_original(cookie.into_owned());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add all of the cookies in `cookies` to this request.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Add `user_id` cookie:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::Cookie;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2018-04-15 02:41:37 +00:00
|
|
|
/// let cookies = vec![Cookie::new("a", "b"), Cookie::new("c", "d")];
|
|
|
|
/// # #[allow(unused_variables)]
|
|
|
|
/// let req = client.get("/").cookies(cookies);
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2018-04-15 02:41:37 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
2019-06-13 01:48:02 +00:00
|
|
|
pub fn cookies(self, cookies: Vec<Cookie<'_>>) -> Self {
|
2018-04-15 02:41:37 +00:00
|
|
|
for cookie in cookies {
|
|
|
|
self.request.cookies().add_original(cookie.into_owned());
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2017-11-30 17:30:31 +00:00
|
|
|
/// Add a [private cookie] to this request.
|
|
|
|
///
|
2018-11-09 07:37:37 +00:00
|
|
|
/// This method is only available when the `private-cookies` feature is
|
|
|
|
/// enabled.
|
2017-11-30 17:30:31 +00:00
|
|
|
///
|
2019-06-13 01:48:02 +00:00
|
|
|
/// [private cookie]: crate::http::Cookies::add_private()
|
2018-11-05 20:29:03 +00:00
|
|
|
///
|
2017-11-30 17:30:31 +00:00
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Add `user_id` as a private cookie:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::Cookie;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-11-30 17:30:31 +00:00
|
|
|
/// # #[allow(unused_variables)]
|
|
|
|
/// let req = client.get("/").private_cookie(Cookie::new("user_id", "sb"));
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-11-30 17:30:31 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
2018-11-09 07:37:37 +00:00
|
|
|
#[cfg(feature = "private-cookies")]
|
2017-11-30 17:30:31 +00:00
|
|
|
pub fn private_cookie(self, cookie: Cookie<'static>) -> Self {
|
|
|
|
self.request.cookies().add_original_private(cookie);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
// TODO: For CGI, we want to be able to set the body to be stdin without
|
|
|
|
// actually reading everything into a vector. Can we allow that here while
|
|
|
|
// keeping the simplicity? Looks like it would require us to reintroduce a
|
|
|
|
// NetStream::Local(Box<Read>) or something like that.
|
|
|
|
|
|
|
|
/// Set the body (data) of the request.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Set the body to be a JSON structure; also sets the Content-Type.
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::ContentType;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
/// # #[allow(unused_variables)]
|
|
|
|
/// let req = client.post("/")
|
|
|
|
/// .header(ContentType::JSON)
|
|
|
|
/// .body(r#"{ "key": "value", "array": [1, 2, 3], }"#);
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-06 20:41:04 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn body<S: AsRef<[u8]>>(mut self, body: S) -> Self {
|
|
|
|
self.data = body.as_ref().into();
|
|
|
|
self
|
|
|
|
}
|
2017-06-30 09:06:03 +00:00
|
|
|
|
|
|
|
/// Set the body (data) of the request without consuming `self`.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// Set the body to be a JSON structure; also sets the Content-Type.
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
/// use rocket::http::ContentType;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-30 09:06:03 +00:00
|
|
|
/// let mut req = client.post("/").header(ContentType::JSON);
|
|
|
|
/// req.set_body(r#"{ "key": "value", "array": [1, 2, 3], }"#);
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-30 09:06:03 +00:00
|
|
|
/// ```
|
|
|
|
#[inline]
|
|
|
|
pub fn set_body<S: AsRef<[u8]>>(&mut self, body: S) {
|
|
|
|
self.data = body.as_ref().into();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Dispatches the request, returning the response.
|
|
|
|
///
|
|
|
|
/// This method consumes `self` and is the preferred mechanism for
|
|
|
|
/// dispatching.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
///
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # rocket::async_test(async {
|
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-30 09:06:03 +00:00
|
|
|
/// let response = client.get("/").dispatch();
|
2020-06-14 15:57:53 +00:00
|
|
|
/// # });
|
2017-06-30 09:06:03 +00:00
|
|
|
/// ```
|
|
|
|
#[inline(always)]
|
2019-08-24 17:27:10 +00:00
|
|
|
pub async fn dispatch(mut self) -> LocalResponse<'c> {
|
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
|
|
|
let r = self.long_lived_request();
|
2019-11-26 16:25:56 +00:00
|
|
|
LocalRequest::_dispatch(self.client, r, self.request, &self.uri, self.data).await
|
2017-06-30 09:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Dispatches the request, returning the response.
|
|
|
|
///
|
|
|
|
/// This method _does not_ consume or clone `self`. Any changes to the
|
|
|
|
/// request that occur during handling will be visible after this method is
|
|
|
|
/// called. For instance, body data is always consumed after a request is
|
|
|
|
/// dispatched. As such, only the first call to `mut_dispatch` for a given
|
|
|
|
/// `LocalRequest` will contains the original body data.
|
|
|
|
///
|
|
|
|
/// This method should _only_ be used when either it is known that
|
|
|
|
/// the application will not modify the request, or it is desired to see
|
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
|
|
|
/// modifications to the request. Prefer to use [`dispatch`] instead.
|
2017-06-30 09:06:03 +00:00
|
|
|
///
|
|
|
|
/// [`dispatch`]: #method.dispatch
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use rocket::local::Client;
|
|
|
|
///
|
2019-08-24 17:27:10 +00:00
|
|
|
/// rocket::async_test(async {
|
2020-06-14 15:57:53 +00:00
|
|
|
/// let client = Client::new(rocket::ignite()).await.unwrap();
|
2017-06-30 09:06:03 +00:00
|
|
|
///
|
2019-08-24 17:27:10 +00:00
|
|
|
/// let mut req = client.get("/");
|
|
|
|
/// let response_a = req.mut_dispatch().await;
|
|
|
|
/// // TODO.async: Annoying. Is this really a good example to show?
|
|
|
|
/// drop(response_a);
|
|
|
|
/// let response_b = req.mut_dispatch().await;
|
|
|
|
/// })
|
2017-06-30 09:06:03 +00:00
|
|
|
/// ```
|
|
|
|
#[inline(always)]
|
2019-08-24 17:27:10 +00:00
|
|
|
pub async fn mut_dispatch(&mut self) -> LocalResponse<'c> {
|
2018-06-20 12:02:12 +00:00
|
|
|
let req = self.long_lived_request();
|
2019-06-13 01:48:02 +00:00
|
|
|
let data = std::mem::replace(&mut self.data, vec![]);
|
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
|
|
|
let rc_req = self.request.clone();
|
2019-08-24 17:27:10 +00:00
|
|
|
LocalRequest::_dispatch(self.client, req, rc_req, &self.uri, data).await
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Performs the actual dispatch.
|
2019-08-24 17:27:10 +00:00
|
|
|
// TODO.async: @jebrosen suspects there might be actual UB in here after all,
|
|
|
|
// and now we just went and mixed threads into it
|
|
|
|
async fn _dispatch(
|
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
|
|
|
client: &'c Client,
|
|
|
|
request: &'c mut Request<'c>,
|
2019-08-14 18:29:55 +00:00
|
|
|
owned_request: Arc<Request<'c>>,
|
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
|
|
|
uri: &str,
|
|
|
|
data: Vec<u8>
|
|
|
|
) -> LocalResponse<'c> {
|
2019-06-30 16:45:17 +00:00
|
|
|
let maybe_uri = Origin::parse(uri);
|
|
|
|
|
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
|
|
|
// First, validate the URI, returning an error response (generated from
|
|
|
|
// an error catcher) immediately if it's invalid.
|
2019-06-30 16:45:17 +00:00
|
|
|
if let Ok(uri) = maybe_uri {
|
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
|
|
|
request.set_uri(uri.into_owned());
|
|
|
|
} else {
|
2018-08-13 07:44:35 +00:00
|
|
|
error!("Malformed request URI: {}", uri);
|
2020-06-14 15:57:51 +00:00
|
|
|
let res = client.manifest().handle_error(Status::BadRequest, request).await;
|
2019-08-24 17:27:10 +00:00
|
|
|
return LocalResponse { _request: owned_request, response: res };
|
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
|
|
|
}
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
// Actually dispatch the request.
|
2020-06-14 15:57:51 +00:00
|
|
|
let response = client.manifest().dispatch(request, Data::local(data)).await;
|
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
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
// If the client is tracking cookies, updates the internal cookie jar
|
|
|
|
// with the changes reflected by `response`.
|
|
|
|
if let Some(ref jar) = client.cookies {
|
|
|
|
let mut jar = jar.write().expect("LocalRequest::_dispatch() write lock");
|
2020-05-27 04:37:30 +00:00
|
|
|
let current_time = time::OffsetDateTime::now_utc();
|
2019-08-24 17:27:10 +00:00
|
|
|
for cookie in response.cookies() {
|
|
|
|
if let Some(expires) = cookie.expires() {
|
|
|
|
if expires <= current_time {
|
|
|
|
jar.force_remove(cookie);
|
|
|
|
continue;
|
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
|
|
|
}
|
2019-06-30 16:45:17 +00:00
|
|
|
}
|
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
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
jar.add(cookie.into_owned());
|
2019-06-30 16:45:17 +00:00
|
|
|
}
|
2019-08-24 17:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalResponse {
|
|
|
|
_request: owned_request,
|
|
|
|
response: response
|
|
|
|
}
|
2017-06-30 09:06:03 +00:00
|
|
|
}
|
2017-06-06 20:41:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 01:48:02 +00:00
|
|
|
impl fmt::Debug for LocalRequest<'_> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2017-06-06 20:41:04 +00:00
|
|
|
fmt::Debug::fmt(&self.request, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 09:06:03 +00:00
|
|
|
/// A structure representing a response from dispatching a local request.
|
|
|
|
///
|
|
|
|
/// This structure is a thin wrapper around [`Response`]. It implements no
|
2018-10-06 13:25:17 +00:00
|
|
|
/// methods of its own; all functionality is exposed via the [`Deref`] and
|
|
|
|
/// [`DerefMut`] implementations with a target of `Response`. In other words,
|
|
|
|
/// when invoking methods, a `LocalResponse` can be treated exactly as if it
|
|
|
|
/// were a `Response`.
|
2017-06-30 09:06:03 +00:00
|
|
|
pub struct LocalResponse<'c> {
|
2019-08-14 18:29:55 +00:00
|
|
|
_request: Arc<Request<'c>>,
|
2017-06-30 09:06:03 +00:00
|
|
|
response: Response<'c>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c> Deref for LocalResponse<'c> {
|
|
|
|
type Target = Response<'c>;
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn deref(&self) -> &Response<'c> {
|
|
|
|
&self.response
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'c> DerefMut for LocalResponse<'c> {
|
|
|
|
#[inline(always)]
|
|
|
|
fn deref_mut(&mut self) -> &mut Response<'c> {
|
|
|
|
&mut self.response
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 01:48:02 +00:00
|
|
|
impl fmt::Debug for LocalResponse<'_> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2017-06-06 20:41:04 +00:00
|
|
|
fmt::Debug::fmt(&self.response, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
// TODO.async: Figure out a way to accomplish this
|
|
|
|
//impl<'c> Clone for LocalRequest<'c> {
|
|
|
|
// fn clone(&self) -> LocalRequest<'c> {
|
|
|
|
// LocalRequest {
|
|
|
|
// client: self.client,
|
|
|
|
// request: self.request.clone(),
|
|
|
|
// data: self.data.clone(),
|
|
|
|
// uri: self.uri.clone()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
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
|
|
|
|
2020-05-27 08:09:12 +00:00
|
|
|
#[cfg(test)]
|
2018-06-20 12:02:12 +00:00
|
|
|
mod tests {
|
2020-05-27 08:09:12 +00:00
|
|
|
use crate::Request;
|
|
|
|
use crate::local::Client;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn clone_unique_ptr() {
|
|
|
|
let client = Client::new(crate::ignite()).unwrap();
|
|
|
|
let r1 = client.get("/");
|
|
|
|
let r2 = r1.clone();
|
|
|
|
|
|
|
|
assert_ne!(
|
|
|
|
r1.inner() as *const Request<'_>,
|
|
|
|
r2.inner() as *const Request<'_>
|
|
|
|
);
|
|
|
|
}
|
2018-06-20 12:02:12 +00:00
|
|
|
|
|
|
|
// #[test]
|
|
|
|
// #[compile_fail]
|
|
|
|
// fn local_req_not_sync() {
|
|
|
|
// fn is_sync<T: Sync>() { }
|
|
|
|
// is_sync::<::local::LocalRequest>();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[test]
|
|
|
|
// #[compile_fail]
|
|
|
|
// fn local_req_not_send() {
|
|
|
|
// fn is_send<T: Send>() { }
|
|
|
|
// is_send::<::local::LocalRequest>();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[test]
|
|
|
|
// #[compile_fail]
|
|
|
|
// fn local_req_not_sync() {
|
|
|
|
// fn is_sync<T: Sync>() { }
|
|
|
|
// is_sync::<::local::LocalResponse>();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[test]
|
|
|
|
// #[compile_fail]
|
|
|
|
// fn local_req_not_send() {
|
|
|
|
// fn is_send<T: Send>() { }
|
|
|
|
// is_send::<::local::LocalResponse>();
|
|
|
|
// }
|
|
|
|
|
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
|
|
|
// This checks that a response can't outlive the `Client`.
|
|
|
|
// #[compile_fail]
|
2018-06-20 12:02:12 +00:00
|
|
|
// fn test() {
|
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
|
|
|
// use {Rocket, local::Client};
|
2018-06-20 12:02:12 +00:00
|
|
|
|
|
|
|
// let rocket = Rocket::ignite();
|
|
|
|
// let res = {
|
|
|
|
// let mut client = Client::new(rocket).unwrap();
|
|
|
|
// client.get("/").dispatch()
|
|
|
|
// };
|
|
|
|
|
|
|
|
// // let client = Client::new(rocket).unwrap();
|
|
|
|
// // let res1 = client.get("/").dispatch();
|
|
|
|
// // let res2 = client.get("/").dispatch();
|
|
|
|
// }
|
|
|
|
|
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
|
|
|
// This checks that a response can't outlive the `Client`.
|
|
|
|
// #[compile_fail]
|
2018-06-20 12:02:12 +00:00
|
|
|
// fn test() {
|
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
|
|
|
// use {Rocket, local::Client};
|
2018-06-20 12:02:12 +00:00
|
|
|
|
|
|
|
// let rocket = Rocket::ignite();
|
|
|
|
// let res = {
|
|
|
|
// Client::new(rocket).unwrap()
|
|
|
|
// .get("/").dispatch();
|
|
|
|
// };
|
|
|
|
|
|
|
|
// // let client = Client::new(rocket).unwrap();
|
|
|
|
// // let res1 = client.get("/").dispatch();
|
|
|
|
// // let res2 = client.get("/").dispatch();
|
|
|
|
// }
|
|
|
|
|
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
|
|
|
// This checks that a response can't outlive the `Client`, in this case, by
|
|
|
|
// moving `client` while it is borrowed.
|
|
|
|
// #[compile_fail]
|
2018-06-20 12:02:12 +00:00
|
|
|
// fn test() {
|
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
|
|
|
// use {Rocket, local::Client};
|
2018-06-20 12:02:12 +00:00
|
|
|
|
|
|
|
// let rocket = Rocket::ignite();
|
|
|
|
// let client = Client::new(rocket).unwrap();
|
|
|
|
|
|
|
|
// let res = {
|
|
|
|
// let x = client.get("/").dispatch();
|
|
|
|
// let y = client.get("/").dispatch();
|
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
|
|
|
// (x, y)
|
2018-06-20 12:02:12 +00:00
|
|
|
// };
|
|
|
|
|
|
|
|
// let x = client;
|
|
|
|
// }
|
|
|
|
|
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
|
|
|
// #[compile_fail]
|
2018-06-20 12:02:12 +00:00
|
|
|
// fn test() {
|
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
|
|
|
// use {Rocket, local::Client};
|
2018-06-20 12:02:12 +00:00
|
|
|
|
|
|
|
// let rocket1 = Rocket::ignite();
|
|
|
|
// let rocket2 = Rocket::ignite();
|
|
|
|
|
|
|
|
// let client1 = Client::new(rocket1).unwrap();
|
|
|
|
// let client2 = Client::new(rocket2).unwrap();
|
|
|
|
|
|
|
|
// let res = {
|
|
|
|
// let mut res1 = client1.get("/");
|
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
|
|
|
// res1.client = &client2;
|
2018-06-20 12:02:12 +00:00
|
|
|
// res1
|
|
|
|
// };
|
|
|
|
|
|
|
|
// drop(client1);
|
|
|
|
// }
|
|
|
|
}
|