Rocket v0.4.0 Release Notes

Release Date: 2018-12-06 // over 5 years ago
  • 🆕 New Features

    🚀 This release includes the following new features:

    👍 [ORM agnostic database support]: https://rocket.rs/v0.4/guide/state/#databases

    📜 [shorthands]: https://api.rocket.rs/v0.4/rocket/http/struct.ContentType.html#method.parse_flexible

    📇 [Metadata]: https://api.rocket.rs/v0.4/rocket_contrib/templates/struct.Metadata.html

    0️⃣ [Default rankings]: https://rocket.rs/v0.4/guide/requests/#default-ranking

    Codegen Rewrite

    The rocket_codegen crate has been entirely rewritten using to-be-stable procedural macro APIs. We expect nightly breakages to drop dramatically, likely to zero, as a result. The new prelude import for Rocket applications is:

    - #![feature(plugin)]
    - #![plugin(rocket_codegen)]
    + #![feature(proc_macro_hygiene, decl_macro)]
    
    - extern crate rocket;
    + #[macro_use] extern crate rocket;
    

    The rocket_codegen crate should not be a direct dependency. Remove it from your Cargo.toml:

    [dependencies]
    - rocket = "0.3"
    + rocket = "0.4"
    - rocket_codegen = "0.3"
    

    💥 Breaking Changes

    🚀 This release includes many breaking changes. These changes are listed below along with a short note about how to handle the breaking change in existing applications when applicable.

    • Route and catcher attributes respect function privacy.

      To mount a route or register a catcher outside of the module it is declared, ensure that the handler function is marked pub or crate.

    • Query handling syntax has been completely revamped.

      A query parameter of <param> is now <param..>. Consider whether your application benefits from the revamped query string handling.

    • The #[error] attribute and errors! macro were removed.

      Use #[catch] and catchers! instead.

    • Rocket::catch() was renamed to Rocket::register().

      Change calls of the form .catch(errors![..]) to .register(catchers![..]).

    • The #[catch] attribute only accepts functions with 0 or 1 argument.

      Ensure the argument to the catcher, if any, is of type &Request.

    • json! returns a JsonValue, no longer needs wrapping.

      Change instances of Json(json!(..)) to json! and change the corresponding type to JsonValue.

    • All environments default to port 8000.

      Manually configure a port of 80 for the stage and production environments for the previous behavior.

    • Release builds default to the production environment.

      Manually set the environment to debug with ROCKET_ENV=debug for the previous behavior.

    • Form and LenientForm lost a lifetime parameter, get() method.

      Change a type of Form<'a, T<'a>> to Form<T> or Form<T<'a>>. Form<T> and LenientForm<T> now implement Deref<Target = T>, allowing for calls to .get() to be removed.

    • ring was updated to 0.13.

      Ensure all transitive dependencies to ring refer to version 0.13.

    • Uri was largely replaced by Origin.

      In general, replace the type Uri with Origin. The base and uri fields of Route are now of type Origin. The &Uri guard is now &Origin. Request::uri() now returns an Origin.

    • All items in rocket_contrib are namespaced behind modules.

      • Json is now json::Json
      • MsgPack is now msgpack::MsgPack
      • MsgPackError is now msgpack::Error
      • Template is now templates::Template
      • UUID is now uuid::Uuid
      • Value is replaced by json::JsonValue
    • TLS certificates require the subjectAltName extension.

      Ensure that your TLS certificates contain the subjectAltName extension with a value set to your domain.

    • Route paths, mount points, and LocalRequest URIs are strictly checked.

      Ensure your mount points are absolute paths with no parameters, ensure your route paths are absolute paths with proper parameter syntax, and ensure that paths passed to LocalRequest are valid.

    • Template::show() takes an &Rocket, doesn't accept a root.

      Use client.rocket() to get a reference to an instance of Rocket when testing. Use Template::render() in routes.

    • Request::remote() returns the actual remote IP, doesn't rewrite.

      Use Request::real_ip() or Request::client_ip() to retrieve the IP address from the "X-Real-IP" header if it is present.

    • Bind variant was added to LaunchErrorKind.

      Ensure matches on LaunchErrorKind include or ignore the Bind variant.

    • Cookies are automatically tracked and propagated by Client.

      For the previous behavior, construct a Client with Client::untracked().

    • UUID was renamed to Uuid.

      Use Uuid instead of UUID.

    • LocalRequest::cloned_dispatch() was removed.

      Chain calls to .clone().dispatch() for the previous behavior.

    • Redirect constructors take a generic type of T: TryInto<Uri<'static>>.

      A call to a Redirect constructor with a non-'static &str of the form Redirect::to(string) should become Redirect::to(string.to_string()), heap-allocating the string before being passed to the constructor.

    • The FromData impl for Form and LenientForm now return an error of type FormDataError.

      On non-I/O errors, the form string is stored in the variant as an &'f str.

    • Missing variant was added to ConfigError.

      Ensure matches on ConfigError include or ignore the Missing variant.

    • The FromData impl for Json now returns an error of type JsonError.

      The previous SerdeError is now the .1 member of the JsonError enum. Match and destruct the variant for the previous behavior.

    • FromData is now emulated by FromDataSimple.

      Change implementations, not uses, of FromData to FromDataSimple. Consider whether your implementation could benefit from transformations.

    • FormItems iterates over values of type FormItem.

      Map using .map(|item| item.key_value()) for the previous behavior.

    • LaunchErrorKind::Collision contains a vector of the colliding routes.

      Destruct using LaunchErrorKind::Collision(..) to ignore the vector.

    • Request::get_param() and Request::get_segments() are indexed by segment, not dynamic parameter.

      Modify the n argument in calls to these functions appropriately.

    • Method-based route attributes no longer accept a keyed path parameter.

      Change an attribute of the form #[get(path = "..")] to #[get("..")].

    • Json and MsgPack data guards no longer reject requests with an unexpected Content-Type

      To approximate the previous behavior, add a format = "json" route parameter when using Json or format = "msgpack" when using MsgPack.

    • Implemented Responder for Status. Removed Failure, status::NoContent, and status::Reset responders.

      Replace uses of Failure(status) with status directly. Replace status::NoContent with Status::NoContent. Replace status::Reset with Status::ResetContent.

    • Config::root() returns an Option<&Path> instead of an &Path.

      For the previous behavior, use config.root().unwrap().

    • Status::new() is no longer const.

      Construct a Status directly.

    • Config constructors return a Config instead of a Result<Config>.

    • ConfigError::BadCWD, Config.config_path were removed.

    • Json no longer has a default value for its type parameter.

    • Using data on a non-payload method route is a warning instead of error.

    • The raw_form_string method of Form and LenientForm was removed.

    • Various impossible Error associated types are now set to !.

    • All AdHoc constructors require a name as the first parameter.

    • The top-level Error type was removed.

    General Improvements

    In addition to new features, Rocket saw the following improvements:

    • Log messages now refer to routes by name.
    • Collision errors on launch name the colliding routes.
    • Launch fairing failures refer to the failing fairing by name.
    • The default 403 catcher now references authorization, not authentication.
    • Private cookies are set to HttpOnly and are given an expiration date of 1 week by default.
    • A Tera templates example was added.
    • All macros, derives, and attributes are individually documented in rocket_codegen.
    • Invalid client requests receive a response of 400 instead of 500.
    • Response bodies are reliably stripped on HEAD requests.
    • Added a default catcher for 504: Gateway Timeout.
    • Configuration information is logged in all environments.
    • Use of unsafe was reduced from 9 to 2 in core library.
    • FormItems now parses empty keys and values as well as keys without values.
    • Added Config::active() as a shorthand for Config::new(Environment::active()?).
    • Address/port binding errors at launch are detected and explicitly emitted.
    • Flash cookies are cleared only after they are inspected.
    • Sync bound on AdHoc::on_attach(), AdHoc::on_launch() was removed.
    • AdHoc::on_attach(), AdHoc::on_launch() accept an FnOnce.
    • Added Config::root_relative() for retrieving paths relative to the configuration file.
    • Added Config::tls_enabled() for determining whether TLS is actively enabled.
    • ASCII color codes are not emitted on versions of Windows that do not support them.
    • Added FLAC (audio/flac), Icon (image/x-icon), WEBA (audio/webm), TIFF (image/tiff), AAC (audio/aac), Calendar (text/calendar), MPEG (video/mpeg), TAR (application/x-tar), GZIP (application/gzip), MOV (video/quicktime), MP4 (video/mp4), ZIP (application/zip) as known media types.
    • Added .weba (WEBA), .ogv (OGG), .mp4 (MP4), .mpeg4 (MP4), .aac (AAC), .ics (Calendar), .bin (Binary), .mpg (MPEG), .mpeg (MPEG), .tar (TAR), .gz (GZIP), .tif (TIFF), .tiff (TIFF), .mov (MOV) as known extensions.
    • Interaction between route attributes and declarative macros has been improved.
    • Generated code now logs through logging infrastructures as opposed to using println!.
    • Routing has been optimized by caching routing metadata.
    • Form and LenientForm can be publicly constructed.
    • Console coloring uses default terminal colors instead of white.
    • Console coloring is consistent across all messages.
    • i128 and u128 now implement FromParam, FromFormValue.
    • The base64 dependency was updated to 0.10.
    • The log dependency was updated to 0.4.
    • The handlebars dependency was updated to 1.0.
    • The tera dependency was updated to 0.11.
    • The uuid dependency was updated to 0.7.
    • The rustls dependency was updated to 0.14.
    • The cookie dependency was updated to 0.11.

    Infrastructure

    • All documentation is versioned.
    • Previous, current, and development versions of all documentation are hosted.
    • The repository was reorganized with top-level directories of core and contrib.
    • The http module was split into its own rocket_http crate. This is an internal change only.
    • All uses of unsafe are documented with informal proofs of correctness.