Commit Graph

223 Commits

Author SHA1 Message Date
Sergio Benitez 8183f63630 Remove lints and associated code from 'rocket_codegen'.
Rust's linting API is incredibly unstable, resulting in unnecessary
breakage to `rocket_codegen`. Rocket's lints are also not as
conservative as would be desired, resulting in spurious warnings. For
these reasons, this commit removes linting from `rocket_codegen`.

These lints will likely be reintroduced as part of a 'rocket_lints'
crate. Factoring the lints out to a separate crate means that lint
breakage can be dealt with by uncommenting the dependency instead of
waiting for a new release or backtracking nightlies. In the same vein,
it will likely improve stability of the 'rocket_codegen' crate.
2017-08-15 11:39:22 -07:00
Rolf Sievers 3a76fe03db Improve commentary on collisions in pastebin example. 2017-08-13 02:56:23 -07:00
Katrina Brock 527051d136 Improve bootstrapping instructions in todo example. 2017-08-13 02:50:28 -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 05944c01af Update diesel example dependency to 0.14. 2017-07-06 02:04:00 -07:00
Sergio Benitez 05a8a93eec Add tests for the 'session' example.
Closes #316.
2017-07-04 14:51:41 -07:00
Sergio Benitez 8eb1fff93f Silence incorrect unmanaged state warnings. 2017-07-03 15:37:24 -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 cdf9ff9bde Remove 'LoggingLevel' from root. Add ConfigError::Io.
This tentatively completes the 'config' rustdocs.
2017-06-18 21:06:41 -07:00
Sergio Benitez ea485e52e8 Update diesel and rusqlite example dependencies. 2017-06-11 02:57:41 -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 3eeae77ed6 Add tests for 'form_kitchen_sink' example.
Closes #62.
2017-06-02 18:46:34 -07:00
Sergio Benitez 6f4c8b1377 Don't create two DB pools in todo example. 2017-06-01 23:03:08 -07:00
Sergio Benitez f1ec552ac5 Make todo example bootstrapping more resilient. 2017-06-01 22:10:05 -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 83002d3203 Don't assume there is an existing DB. 2017-05-26 17:12:57 -07:00
Sergio Benitez 614ec1359e Add tests for 'todo' example. 2017-05-26 16:52:17 -07:00
Sergio Benitez 6a7903a220 Add tests for 'raw_upload' example. 2017-05-24 22:56:57 -07:00
Sergio Benitez 732cb26eb5 Add tests for 'stream' example. 2017-05-24 22:45:03 -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
Anton Pirker 781477fff1 Rename 'session_key' config parameter to 'secret_key'.
Resolves #220.
2017-05-12 17:24:25 -07:00
Lance Carlson 13061e9062 Update uuid dependency to 0.5. 2017-05-05 12:20:36 -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 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 d6e86be1b0 Make route collisions a hard error.
This is a breaking change. Previously, route collisions were warnings.
2017-04-18 17:42:44 -07:00
Sergio Benitez f97b02dda6 Note the extras in the config example. 2017-04-18 17:32:32 -07:00
Sergio Benitez 6dc21e5380 Add support for configurable size limits. 2017-04-18 00:25:13 -07:00
Sergio Benitez 7d2a114280 Set version of managed_queue example to 0.0.0. 2017-04-14 14:58:17 -07:00
Sergio Benitez 8d14cd571c Tidy up managed_queue example. 2017-04-14 14:54:19 -07:00
Stephan Buys b4586f62ee Add managed_queue example and tests. 2017-04-14 14:54:14 -07:00
Sergio Benitez e6615af7e6 Add tests for pastebin example. 2017-04-14 14:39:17 -07:00
Sergio Benitez 3bebdcc53d Add Response::body_string(). Use it in all tests. 2017-04-14 01:59:28 -07:00
Sergio Benitez 0d674c57fd Return `HeaderMap` from Response::headers(). Remove Response::header_values().
This is a breaking change. A call to `Response::headers()` can be
replaced with `Response::headers().iter()`. A call to
`Response::header_values()` can be replaced with
`Response::headers().get()`.
2017-04-14 01:21:06 -07:00
Fabrice Desré da1f6264e4 Enable the "tls" feature in the hello_tls example. 2017-04-13 17:38:56 -07:00
Sergio Benitez 6f29696b4f Make TLS misconfig an error. Always print launch message. 2017-04-13 01:16:09 -07:00
Sergio Benitez 1516ca4fb6 Initial TLS support.
This commit introduces TLS support, provided by `rustls` and a fork of
`hyper-rustls`. TLS support is enabled via the `tls` feature and
activated when the `tls` configuration parameter is set. A new
`hello_tls` example illustrates its usage.

This commit also introduces more robust and complete configuration
settings via environment variables. In particular, quoted string,
array, and table (dictionaries) based configuration parameters can now
be set via environment variables.

Resolves #28.
2017-04-13 00:18:31 -07:00
Sergio Benitez cf47daa8e1 Return 404 on missing static file in todo example. 2017-04-12 02:58:45 -07:00
Sergio Benitez 7c19bf784d Allow form field renaming via #[form(field = "name")] attribute. 2017-04-03 19:06:30 -07:00
Sergio Benitez f5ec470a7d Use the `RawStr` type for raw parameter strings.
This is a breaking change.

The `&str` type no longer implements `FromParam`. The `&RawStr` type
should be used in its place.
2017-03-31 00:18:58 -07:00
Sergio Benitez 0c44e44641 Use the `RawStr` type for all form raw strings.
This is a breaking change.

This commit introduces `RawStr` to forms. In particular, after this
commit, the `&str` type no longer implements `FromFormValue`, and so it
cannot be used as a field in forms. Instad, the `&RawStr` can be used.

The `FormItems` iterator now returns an `(&RawStr, &RawStr)` pair.
2017-03-30 23:06:53 -07:00
Sergio Benitez 301257623c Update diesel and rusqlite example dependencies. 2017-03-30 02:02:09 -07:00
Sergio Benitez c58ca894b7 Initial implementation of content negotiation via `Accept`.
This is a breaking change.

This commit changes the meaning of the `format` route attribute when
used on non-payload carrying requests (GET, HEAD, CONNECT, TRACE, and
OPTIONS) so that it matches against the preferred media type in the
`Accept` header of the request. The preferred media type is computed
according to the HTTP 1.1 RFC, barring a few specificty rules to come.
2017-03-29 04:08:53 -07:00
Sergio Benitez 9160483554 A route with unspecified query parameters accepts any.
This is a breaking change. It modifies collisions with respect to query
parameters as well as the default ranking of routes.

A route that does not specify query parameters will now match against
requests with _and without_ query parameters, assuming all other
elements of the route match as well. A route that _does_ specify query
parameters will only match requests with query parameters; this remains
true.

To accommodate this change in the most natural manner possible, the
default rankings of routes have changed as illustrated below:

  |-------------+-------+----------+---------------|
  | static path | query | new rank | previous rank |
  |-------------+-------+----------+---------------|
  | yes         | yes   | -4       | 0             |
  | yes         | no    | -3       | 0             |
  | no          | yes   | -2       | 1             |
  | no          | no    | -1       | 1             |
  |-------------+-------+----------+---------------|

In other words, the most specific routes, with preference for paths over
queries, are ranked highest (lower number).
2017-03-27 03:52:26 -07:00
Sergio Benitez 65da988962 Return a `LaunchError` from `launch` when launching fails.
This is a (minor) breaking change. If `rocket.launch()` is the last expression
in a function, the return type will change from `()` to `LaunchError`. A simple
workaround that preserves the previous functionality is to simply add a
semicolon after `launch()`: `rocket.launch();`.

resolves #34
2017-03-15 22:10:09 -07:00
Sergio Benitez 7139941e04 Ensure no files have trailing whitespace. 2017-03-15 19:26:15 -07:00
Sergio Benitez 5434f467a9 Check msgpack example version to 0.0.0. 2017-03-08 17:56:08 -08:00