Commit Graph

452 Commits

Author SHA1 Message Date
Sergio Benitez
17b8ab694c Use 'FromUriParam' trait for better ergonomics in 'uri!'. 2017-09-14 22:13:07 -07:00
Sergio Benitez
3bf577db6e Handle segments parameters in 'uri!'.
This commit also moves the 'uri' module into its own directory,
includes the beginning of the 'FromUriParam' trait, and abandons the
'url' crate in favor of 'percent_encoding' for percent encoding.
2017-09-14 22:13:07 -07:00
Sergio Benitez
5efc4b1096 Rename 'URI' to 'Uri'. 2017-09-14 22:13:07 -07:00
Sergio Benitez
b033a2e2a9 Document 'UriDisplay' trait. 2017-09-14 22:13:03 -07:00
Sergio Benitez
909eae894a Don't implement 'UriDisplay' for all 'T: Display'.
We don't know if that 'Display' implementation is URI safe, so using
it blindly could result in generating bad URIs.
2017-09-14 22:12:54 -07:00
Sergio Benitez
f623d92484 Implement 'FromParam' for 'Cow<str>'. 2017-09-14 22:12:54 -07:00
Sergio Benitez
d8acd04789 Fix mountpoint in 'mount_point' test. 2017-09-14 22:12:47 -07:00
Sergio Benitez
a9dd52a4fb Ensure mount points are absolute. 2017-09-14 22:12:03 -07:00
Sergio Benitez
084481a84e Initial implementation of typed URIs.
This is a breaking change. All Rocket applications using code
generation must now additionally declare usage of the 'decl_macro'
feature.
2017-09-14 22:10:25 -07:00
Sergio Benitez
f18fa81a4e Shorten 'handle' function signature to one line. 2017-09-09 00:54:30 -07:00
Sergio Benitez
8dcbca5cda Relate a 403 status to authorization, not authentication.
Resolves #416.
2017-09-09 00:34:43 -07:00
Sergio Benitez
b5c2187249 Use '&*' instead of 'as_ref()' for 'String' to '&str' ref. 2017-09-07 16:55:38 -07:00
David Hotham
bd08d50f59 Remove reliance on 'lookup_host'. 2017-09-07 16:45:06 -07:00
Lukas Kalbertodt
329711db3b Use 'debug_struct' to improve 'Config' 'Debug' impl.
Using the method `debug_struct()` of `fmt::Formatter` takes care of
the exact formatting for us. Additionally, it also handles the
"alternate" form of printing enabled with '#'. In the struct case it
prints the struct on multiple lines instead of just one.

This commit also changes the output slightly. Before, the field
`log_level` was printed with `log: {}`. This commit replaces "log"
with "log_level". Additionally, the value of `environment` is now
printed as a struct field instead of being combined with the struct
name.
2017-09-07 11:18:47 -07:00
Ram
0930304aad Implement 'From<Status>' for 'Failure'.
Resolves #399.
2017-09-07 11:03:57 -07:00
Joshua Rombauer
e656ec87d7 Clarify 'on_request' Fairing documentation. 2017-09-07 10:52:31 -07:00
QuietMisdreavus
62f96331e2 Indent comments to prevent being commonmark code blocks. 2017-09-07 10:41:35 -07:00
Sergio Benitez
37886ce3a2 Only log nonempty fairing collections. 2017-09-04 20:31:35 -07:00
Sergio Benitez
eb3d3dcfeb Don't print emojis when colors are disabled. 2017-09-04 20:22:10 -07:00
Sergio Benitez
ae46d27129 Clean-up code style in 'lib/rocket.rs'. 2017-09-04 20:11:10 -07:00
Sergio Benitez
2f84d4b18a Add 'Config::root_relative()'. Make TLS config paths root-relative.
Prior to this commit, relative paths to TLS PEM files were incorrectly
treated as being relative to the CWD as opposed to the Rocket config
file, when present. This commit resolves the issue.
2017-09-04 19:01:26 -07:00
Sergio Benitez
2b3aa01463 Improve I/O and BadType config error messages. 2017-08-31 19:05:35 -07:00
Linus Heckemann
c63bb67fb9 Avoid sorting routes on every add. 2017-08-29 17:24:09 -07:00
Sergio Benitez
4df7ce6bf5 Propogate route names through codegen to runtime.
This commit modifies `codegen` so that a route's name (the name of the
route handler) is stored in the generated static route information
structure and later propogated into the corresponding `Route`
structure.

The primary advantage of this change is an improvement to debug and
error messages which now include route names. The collision error
message, in particular, has been improved dramatically in this commit.
Additionally, the `LaunchError::Collision` variant now contains a
vector of the colliding routes.
2017-08-20 10:55:23 -07:00
adrian5
f66780bd9e Add missing comma in 'FromParam' docs. 2017-08-14 11:49:59 -07:00
Sergio Benitez
31cbe65704 Fix example in 'Request::guard()' documentation.
Resolves #378.
2017-08-13 03:13:20 -07:00
Daiki Mizukami
667a057e39 Add 'Box' conversion methods to 'UncasedStr'. 2017-08-13 02:17:53 -07:00
Sergio Benitez
721f6204ea Update lints for latest nightly, '2017-08-10'. 2017-08-11 09:14:54 -07:00
Sergio Benitez
9108e79fb9 Fix typo in 'Limits' docs: anf -> and. 2017-08-04 20:21:21 -07:00
Sergio Benitez
0b7d9f4602 Remove unused doc comments. 2017-08-02 17:48:00 -07:00
Ian Létourneau
84fe23a9fb Fix spelling of "corresponding" in 'status' docs. 2017-07-27 01:58:25 -04:00
Sergio Benitez
b276e1d51f Enable ASCII escape sequences in Windows consoles. 2017-07-26 22:54:45 -04:00
Sergio Benitez
3abc813605 Use 'AtomicIsize', not 'Cell', in URI. 2017-07-21 17:00:38 -04:00
Christian Legnitto
362afdc445 Fix spelling of "instantiated" in rustdocs. 2017-07-18 09:35:37 -04:00
Flarp
69afb5c4a3 Fix typo in 'NotFound' docs: 404, not 400. 2017-07-17 14:10:52 -04:00
Tommy Ip
ae406cf0ca Fix 'clusure' typo in fairings guide and ad_hoc.rs.
Fixes #348.
2017-07-15 00:36:41 -07:00
Stuart Hinson
b3f41f248c Update 'Fairing' example to reflect doc's content. 2017-07-15 00:35:25 -07:00
Yong Wen Chua
10efcb1af9 Always implement 'Responder' with 'r instead of 'static. 2017-07-14 09:43:22 -07:00
Sergio Benitez
722959ee29 Use a parametric lifetime in 'Responder' example. 2017-07-14 09:42:33 -07:00
Sergio Benitez
897313730d Use TitleCase for all 'content::' struct names. 2017-07-12 15:21:45 -07:00
Sergio Benitez
65886c8c4e Rename 'contrib::JSON' to 'contrib::Json'. 2017-07-12 15:11:41 -07:00
Sergio Benitez
70bc97c322 Rename 'APIKey' in example docs to 'ApiKey'. 2017-07-12 14:53:08 -07:00
Sergio Benitez
85846c2af1 Use 'hyper_sync_rustls' for hyper/rustls interop. 2017-07-12 04:13:46 -07:00
Sergio Benitez
5a632a4d27 Always log a request's 'format' when available. 2017-07-11 04:35:05 -07:00
Sergio Benitez
6050eb5169 Update for 2017-07-09. 'associated_consts' is stable. 2017-07-09 22:00:01 -07:00
Sergio Benitez
90d85d3c06 Implement 'Fairing' for 'Arc<T>'. Fix various doc issues. 2017-07-06 20:48:25 -07:00
Sergio Benitez
58445be4ff Add 'LocalRequest' cookies as original. 2017-07-04 14:51:00 -07:00
Sergio Benitez
6df5564983 Fix 'IntoOutcome' implementations for 'Option' and 'Result'.
Fixes #334.
2017-07-04 14:05:16 -07:00
Sergio Benitez
462f1f9298 Add a 'status::NotFound' responder. 2017-07-04 02:43:00 -07:00
Sergio Benitez
436bd99376 Use a streamed 'Responder' body for 'File', as before. 2017-07-04 01:34:43 -07:00
Sergio Benitez
da9bf1189f Add variant checker methods to 'StatusClass'. 2017-07-04 01:33:52 -07:00
Sergio Benitez
15c2ef7aaa Derive 'PartialOrd', 'Ord', and 'Hash' for 'State'. 2017-07-03 15:39:24 -07:00
Sergio Benitez
a94dc9a270 Document 'IntoOutcome'. 2017-07-03 15:29:12 -07:00
Sergio Benitez
00df2846d7 Improve 'State' docs. 2017-07-03 15:13:21 -07:00
Sergio Benitez
0fa2c459d9 Remove 'more_io_inner_methods' feature: it's been stabilized. 2017-07-03 02:39:32 -07:00
Sergio Benitez
77c51ff43f Use the '!' type for 'str::FromForm::Error'. 2017-07-03 02:25:02 -07:00
Sergio Benitez
82a2d2f44e Implement 'FromForm' for 'Option' and 'Result'. 2017-07-03 02:13:35 -07:00
Sergio Benitez
02f466fa17 Inline 'Method::supports_payload()'. 2017-07-03 01:38:14 -07:00
Sergio Benitez
1f367af704 Fix broken link to 'LaunchError' in 'Rocket' docs. 2017-06-30 13:50:36 -07:00
Sergio Benitez
beb5ca14cf Improve 'Route' documentation. 2017-06-30 13:17:40 -07:00
Sergio Benitez
3310c19960 Add examples for 'Data' methods. 2017-06-30 02:18:56 -07:00
Sergio Benitez
0a772286a9 Fully document the 'local' module. 2017-06-30 02:06:03 -07:00
Sergio Benitez
06ad52157d Use Into<Value> from 'toml' instead of 'IntoValue'. 2017-06-29 14:04:54 -07:00
Sergio Benitez
ef4c2fd989 Fix 'Accept' PartialEq impl. Finish 'Request' docs. 2017-06-24 21:00:50 -07:00
Sergio Benitez
dfbd3265f3 Improve fairing and request/data guard docs. 2017-06-24 18:43:10 -07:00
Sergio Benitez
150aef7764 Impl 'try' for 'Outcome'. Document 'Cookies'.
The 'try' impl for 'Outcome' allows the '?' operator to be used with
'Outcome' values. This is likely to make 'FromRequest' and 'FromData'
implementations more ergonomic.

This commit also expands the 'IntoOutcome' trait. It is now
implemented for 'Option'. It also now includes an additional
'or_forward' method.
2017-06-24 02:49:31 -07:00
Sergio Benitez
0376fb5fe5 Rename 'WeightedMediaType' to 'QMediaType'. More docs.
This commit nears completion of the 'http' module docs.
2017-06-22 04:29:59 -07:00
Sergio Benitez
ce363810c5 Disable coloring when output isn't a tty. 2017-06-19 18:29:26 -07:00
Sergio Benitez
6a7fde6d70 Initial cleanup of 'http' docs. Add 'handler::Outcome' docs.
This commit also changes the signature of the 'ContentType'
'from_extension" method so that it returns an 'Option<ContentType>' as
opposed to 'ContentType'.

This commit also disallows negative quality values in 'Accept' media
types.
2017-06-19 17:32:33 -07:00
Sergio Benitez
cdf9ff9bde Remove 'LoggingLevel' from root. Add ConfigError::Io.
This tentatively completes the 'config' rustdocs.
2017-06-18 21:06:41 -07:00
Sergio Benitez
a3ea9d0f9a Add support for lenient forms via 'LenientForm'.
This commit changes the 'FromForm' trait in two ways:

  1. The singular method is now named 'from_form'.
  2. The method takes a second parameter: 'strict: bool'.

The 'strict' parameter is used to specify whether form parsing should
be strict or not (i.e. lenient). When parsing is lenient, extra form
fields do not result in an error. This lenient behavior is used by a
new 'LenientForm' data guard type to request lenient form parsing. The
behavior for 'Form' remains unchanged.

Resolves #242.
2017-06-18 01:59:22 -07:00
Sergio Benitez
3fcf6c43dc Clean up LaunchError docs. Add Rocket::{config, routes} example.
This commit also:

  * Cleans up the stored URIs in routes.
  * Removes LaunchError as a root export.
  * Adds a URI::base() method.
2017-06-12 15:11:01 -07:00
Sergio Benitez
7cf3367183 Document the Limits structure. Change default workers.
The default workers config parameter is now [num_cpus * 2].
2017-06-11 03:39:30 -07:00
Sergio Benitez
8badc73c4b Update toml to 0.4. Add Config::get_datetime. 2017-06-11 02:20:57 -07:00
Sergio Benitez
9a297f776b Tidy up broken links. Set 'html_root_url'. 2017-06-11 01:03:59 -07:00
Sergio Benitez
d09920c021 Emit warning when no 'secret_key' is set in prod. 2017-06-08 23:33:16 -07:00
Sergio Benitez
b8ba7b855f Remove Session in favor of private cookies. New testing API.
Sessions
--------

This commit removes the `Session` type in favor of methods on the
`Cookies` types that allow for adding, removing, and getting private
(signed and encrypted) cookies. These methods provide a superset of
the functionality of `Session` while also being a minimal addition to
the existing API. They can be used to implement the previous `Session`
type as well as other forms of session storage. The new methods are:

  * Cookie::add_private(&mut self, Cookie)
  * Cookie::remove_private(&mut self, Cookie)
  * Cookie::get_private(&self, &str)

Resolves #20

Testing
-------

This commit removes the `rocket::testing` module. It adds the
`rocket::local` module which provides a `Client` type for local
dispatching of requests against a `Rocket` instance. This `local`
package subsumes the previous `testing` package.

Rocket Examples
---------------

The `forms`, `optional_result`, and `hello_alt_methods` examples have
been removed. The following example have been renamed:

  * extended_validation -> form_validation
  * hello_ranks -> ranking
  * from_request -> request_guard
  * hello_tls -> tls

Other Changes
-------------

This commit also includes the following smaller changes:

  * Config::{development, staging, production} constructors have been
    added for easier creation of default `Config` structures.
  * The `Config` type is exported from the root.
  * `Request` implements `Clone` and `Debug`.
  * `Request::new` is no longer exported.
  * A `Response::body_bytes` method was added to easily retrieve a
    response's body as a `Vec<u8>`.
2017-06-08 17:34:50 -07:00
Sergio Benitez
504a7fe583 Update to yansi 0.3 for proper Debug formatting.
This commit also improves the format of TOML parsing error messages.

Fixes #310.
2017-06-06 13:56:13 -07:00
Sergio Benitez
a6c4d053ad Switch to 'yansi' for all terminal coloring.
Resolves #299.
2017-06-01 22:10:05 -07:00
Sergio Benitez
923b84f42c Remove outdated comment FIXME. 2017-05-29 18:10:07 -07:00
Sergio Benitez
6a9421935e Add 'Request::route' method to get active 'Route'.
This commit also adds the `base` field to `Route` which allows the
base mount point to be retrieved. Finally, this commits adds an
implementation of `FromRequest` for `Route` which returns the active
route if one is available or forwards otherwise.

This commit is a breaking change: it makes `Request` and `MockRequest`
invariant over the lifetime `'r`. While this shouldn't affect most
applications, it may affect some.

Resolves #108.
2017-05-29 18:00:33 -07:00
Sergio Benitez
299a422cbc Optimize MediaType::Display, ContentType::Into<Header>, and precheck.
Differential and causal profiling determined that 35% of `Hello, world!`
dispatch time was spent rendering `Content-Type` due to many calls to `fmt` in
`MediaType::Display` and an allocation in `ContentType::Into<Header>`. This
change reduces the number of calls to `fmt` to 1 in `MediaType::Display` and
removes the allocation in `Into<Header>` for known media types.

This change also caches a `Rocket` "precheck" so that pre-dispatch checks are
done only a single time for a given `Rocket` instance, further reducing
`MockRequest::dispatch_with` time for "Hello, world!" by roughly 15%.
2017-05-23 16:41:38 -07:00
Sergio Benitez
d93d366ce7 Remove use of type_ascription feature. 2017-05-20 11:51:17 -07:00
Sergio Benitez
6c00d362c0 Add ResponseBuilder::raw_body. Use OrderMap for HeaderMap. 2017-05-20 11:41:44 -07:00
Sergio Benitez
42c98fe1c3 Rename 'extra' Request field to 'state'. 2017-05-19 19:38:56 -07:00
Sergio Benitez
fc7d51d010 Check before dumping data in kill_stream. 2017-05-19 19:38:28 -07:00
Sergio Benitez
4cab891fda Default session removal cookie path to '/'.
Fixes #295.
2017-05-19 03:46:19 -07:00
Sergio Benitez
9b955747e4 Remove config global state. Use Responder::respond_to.
This commit includes two major changes to core:

  1. Configuration state is no longer global. The `config::active()`
     function has been removed. The active configuration can be
     retrieved via the `config` method on a `Rocket` instance.

  2. The `Responder` trait has changed. `Responder::respond(self)` has
     been removed in favor of `Responder::respond_to(self, &Request)`.
     This allows responders to dynamically adjust their response based
     on the incoming request.

Additionally, it includes the following changes to core and codegen:

  * The `Request::guard` method was added to allow for simple
    retrivial of request guards.
  * The `Request::limits` method was added to retrieve configured
    limits.
  * The `File` `Responder` implementation now uses a fixed size body
    instead of a chunked body.
  * The `Outcome::of<R: Responder>(R)` method was removed while
    `Outcome::from<R: Responder(&Request, R)` was added.
  * The unmounted and unmanaged limits are more cautious: they will only
    emit warnings when the `Rocket` receiver is known.

This commit includes one major change to contrib:

  1. To use contrib's templating, the fairing returned by
     `Template::fairing()` must be attached to the running Rocket
     instance.

Additionally, the `Display` implementation of `Template` was removed. To
directly render a template to a `String`, the new `Template::show`
method can be used.
2017-05-19 03:29:08 -07:00
Sergio Benitez
28a1ef0916 Fairings, v3.
Modifying the `Rocket` structure just before launch doesn't make sense for
several reasons: 1) those affects can't influence the launch, and 2) they won't
be observed in tests. Thus, an `Attach` fairing kind was added that ameliorates
these issues.
2017-05-17 01:39:36 -07:00
Sergio Benitez
9c9740f966 Fairings v2. 2017-05-14 21:46:01 -07:00
Sergio Benitez
9a7484f7a8 Reclose connection on unread data. Minimum nightly is 1.19. 2017-05-13 02:00:35 -07:00
Anton Pirker
781477fff1 Rename 'session_key' config parameter to 'secret_key'.
Resolves #220.
2017-05-12 17:24:25 -07:00
Sergio Benitez
5e345e99d0 Make I/O and parsing TLS file errors distinct. 2017-05-12 14:38:18 -07:00
Sergio Benitez
30fac32978 Upgrade dependencies to Serde 1.0.
Closes #272.
Resolves #273.
2017-04-24 17:37:18 -07:00
Sergio Benitez
40d11929d7 Optimize the creation of the Data structure. 2017-04-24 01:33:00 -07:00
Sergio Benitez
45eb475607 Use unboxed WrappedStream. 2017-04-22 22:17:21 -07:00
Sergio Benitez
0a8de2f0a6 Ensure that all raw HTTP data is transfer-decoded. 2017-04-22 22:06:33 -07:00
Sergio Benitez
1e5a1b8940 Remove 'testing' feature. Close stream on network error.
This is a breaking change.

The `testing` feature no longer exists. Testing structures can now be
accessed without any features enabled.

Prior to this change, Rocket would panic when draining from a network
stream failed. With this change, Rocket force closes the stream on any
error.

This change also ensures that the `Fairings` launch output only prints
if at least one fairing has been attached.
2017-04-20 20:36:12 -07:00
Sergio Benitez
ac0c78a0cd Initial implementation of fairings: structured middleware for Rocket.
Closes #55.
2017-04-20 13:44:19 -07:00
Sergio Benitez
41386cfb78 Display the port that was resolved, not configured. 2017-04-19 02:51:44 -07:00