Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
=0.5.0-rc.4
->=0.5.1
Release Notes
rwf2/Rocket (rocket)
v0.5.1
Compare Source
This release contains the following crate updates:
rocket
0.5.1
rocket_db_pools
0.2.0
rocket_dyn_templates
0.2.0
rocket_ws
0.1.1
rocket
0.5.1
The following
char
andstd::ops::Range
types now implementFromForm
:char
Range<T: FromForm>
withstart
andend
fieldsRangeFrom<T: FromForm>
withstart
fieldRangeTo<T: FromForm>
withend
fieldRangeToInclusive<T: FromForm>
withend
field[T; N]
,Vec<T>
, and[u8]
can now be passed touri!
.The guide now includes a deploying section.
The
FromForm
derive now properly records errors involving entire forms.FromForm
derive can now be used in code emitted bymacro_rules!
macros.(fix #2668 via 52de9a) [
TempFile
] now ensures it flushes beforebeing persisted.
rocket_db_pools
0.2.0
SQLite extensions are now supported in
sqlx_sqlite
.Use a database configuration option of
extensions
to specify extensions:This option is only supported by the
sqlx_sqlite
driver.(breaking)
deadpool
was updated to0.13
.(breaking) The
Config
structure has a new
extensions
field.rocket_dyn_templates
0.2.0
Support for
minijinja
2.0
templates was introduced.Templates with an extension of
.j2
are recognized and rendered withMinijinja.
(breaking)
handlebars
was updated to5.1
.rocket_ws
0.1.1
Introduced [
WebSocket::accept_key()
][WebSocket::accept_key()] method.tungstenite
was updated to0.21
.General Changes
The
rust-version
for all crates was updated to1.64
.This reflects the correct MSRV required to build
rocket
0.5.0
.License files are now present in all published crates.
v0.5.0
Compare Source
Major Features and Improvements
This release introduces the following major features and improvements:
async
/await
][async/await].rocket_ws
][rocket_ws].context.
shutdown fairings.
rocket_db_pools
][rocket_db_pools].Certificate
][Certificate]s.h2
ALPN.json
,msgpack
, anduuid
rocket_contrib
features into core.Shield
][Shield]: security and privacy headers for all responses.uri!
][uri!] macro.serde
][support for serde] for built-in guards and types.#[launch]
and#[rocket::main]
.#[catch(default)]
, which handle any status code.TempFile
][TempFile] data and form guard for automatic uploading to a temporary file.Capped<T>
][Capped] data and form guard which enables detecting truncation due to data limits.uri!
][uri!].Reference
][Reference]s.<param..>
) which match zero segments.local_cache!
][local_cache!] macro for request-local storage of non-uniquely typed values.CookieJar
][CookieJar] without "one-at-a-time" limitations.2.mebibytes()
.#[derive(Responder)]
.chat
][chat] application.Support for Rust Stable
As a result of support for Rust stable (Rust 2021 Edition and beyond),
#![feature(..)]
crate attributes are no longer required to use Rocket. Thecomplete canonical example with a single
hello
route becomes:See a
diff
of the changes from v0.4.Breaking Changes
This release includes many breaking changes. For a walkthrough guide on handling these changes, see
the v0.4 to v0.5 migration guide. The most significant changes are listed below.
Silent Changes
These changes are invisible to the compiler and will not yield errors or warnings at compile-time.
We strongly advise all application authors to review this list carefully.
sleep()
,Mutex
,RwLock
, etc.) may preventthe server from making progress and should be avoided, replaced with an
async
variant, orperformed in a worker thread. This is a consequence of Rust's cooperative
async
multitasking.For details, see the new multitasking section of the guide.
ROCKET_ENV
is nowROCKET_PROFILE
. A warning is emitted a launch time if the former is set.debug
, notdev
.release
, notprod
.ROCKET_LOG
is nowROCKET_LOG_LEVEL
. A warning is emitted a launch time if the former is set.ROCKET_ADDRESS
accepts only IP addresses, no longer resolves hostnames likelocalhost
.ROCKET_CLI_COLORS
accepts booleanstrue
,false
in place of strings"on"
,"off"
.secrets
is enabled in non-debug
profiles without a configuredsecret_key
.template_dir
is reported as an error at launch time.FileServer::new()
][FileServer::new()] fails immediately if the provided directory does not exist.-12
to-1
. There is no breaking change if only code generatedroutes are used. Manually configured routes with negative ranks may collide or be considered in
a different order than before.
:
are properly recognized as invalid and rejected.Segments
iterator now returns percent-decoded&str
s.Form
guard][Form guard]. Use [Strict
][Strict] for the previous behavior.Option<T>
form guard defaults toNone
instead of the default value forT
.413 Payload Too Large
status is returned to the client.Accept
header.
true
: the query string?f
is the same as?f=true
.Created<R>
][Created] does not automatically send anETag
header ifR: Hash
. Use[
Created::tagged_body
][Created::tagged_body] instead.FileServer
now forwards when a file is not found instead of failing with404 Not Found
.Shield
][Shield] is enabled by default. You may need to disable or change policies if your applicationdepends on typically insecure browser features or if you wish to opt-in to different policies
than the defaults.
CookieJar
][CookieJar]get()
s do not return cookies added during request handling. See[
CookieJar
#pending][CookieJar#pending].Hash
impl
s forMediaType
andContentType
no longer consider media type parameters.FromForm
implementations ofVec
andMap
s are now properly lenient.[
and]
characters are now accepted in URI paths.[
and]
characters are no longer encoded by [uri!
][uri!].Secure
cookie flag is set by default for all cookies when serving over TLS.SameSite
set toLax
by default.MediaType::JavaScript
][MediaType::JavaScript] is nowtext/javascript
.Contrib Graduation
The
rocket_contrib
crate is deprecated and the functionality moved to otherrocket
crates. Thecontrib deprecation upgrade guide provides a walkthrough on migrating. The relevant changes are:
rocket_contrib
were merged intorocket
itself:json
,msgpack
, anduuid
are now [features ofrocket
][features of rocket].rocket_contrib::json
to [rocket::serde::json
][rocket::serde::json].rocket_contrib::msgpack
to [rocket::serde::msgpack
][rocket::serde::msgpack].rocket_contrib::uuid
to [rocket::serde::uuid
][rocket::serde::uuid].rocket_contrib::helmet
to [rocket::shield
][rocket::shield]. [Shield
][Shield] is enabled by default.rocket_contrib::serve
to [rocket::fs
][rocket::fs],StaticFiles
to [rocket::fs::FileServer
][rocket::fs::FileServer].Uuid
andJsonValue
wrapper types.Shield
that are no longer respected by browsers.rocket_contrib
are now provided by separate crates:rocket_contrib::templates
with [rocket_dyn_templates
][rocket_dyn_templates].rocket_contrib::databases
with [rocket_sync_db_pools
][rocket_sync_db_pools] and [rocket_db_pools
][rocket_db_pools].rocket
.rocket_contrib::databases::DbError
is nowrocket_sync_db_pools::Error
.redis
,mongodb
, andmysql
integrations which have upstreamasync
drivers.#[database]
attribute generates an [
async run()
][async run()] method instead ofDeref
implementations.General
The following breaking changes apply broadly and are likely to cause compile-time errors.
Rocket
][Rocket] is now generic over a phase marker:Rocket<Build>
,Rocket<Ignite>
,Rocket<Orbit>
, orRocket<P: Phase>
asneeded.
Build
,Ignite
,Orbit
order.rocket::ignite()
is now [rocket::build()
][rocket::build()] and returns aRocket<Build>
.Rocket::ignite()
][Rocket::ignite()] transitions to theIgnite
phase. This is run automatically on launch asneeded.
ignite
fairings, and verifies sentinels.Rocket::launch()
][Rocket::launch()] transitions into theOrbit
phase and starts the server.Request::rocket()
][Request::rocket()] that refer to a live Rocket instance return an&Rocket<Orbit>
.async
:attach
fairings withignite
fairings. Unlikeattach
fairings, which ranimmediately at the time of attachment,
ignite
fairings are run when transitioning into theIgnite
phase.launch
fairings withliftoff
fairings.liftoff
fairings are always run, even inlocal clients, after the server begins listening and the concrete port is known.
ROCKET_ENV
is superseded byROCKET_PROFILE
.ROCKET_LOG
is superseded byROCKET_LOG_LEVEL
.dev
,stage
, andprod
profiles carry nospecial meaning.
debug
andrelease
profiles are the default profiles for the debug and releasecompilation profiles.
default
profile specifies defaults for all profiles.global
profile has highest precedence, followed by the selected profile, followed bydefault
.LoggingLevel
to [LogLevel
][LogLevel].Error
][Error] structure.workers
tousize
fromu16
.keep_alive
: it is disabled with0
, notfalse
oroff
.secrets
feature (for private cookies) by default.Figment
.ConfigBuilder
: all fields of [Config
][Config] are public with constructors for each fieldtype.
async
:FromRequest
][FromRequest], [Fairing
][Fairing], [catcher::Handler
][catcher::Handler], [route::Handler
][route::Handler], and [FromData
][FromData] use#[async_trait]
.NamedFile::open
][NamedFile::open] is now anasync
function.Request::local_cache_async()
][Request::local_cache_async()] for use in async request guards.Response
bodies must be [AsyncRead
][AsyncRead] instead ofRead
.Response
bodies must be [AsyncSeek
][AsyncSeek] instead ofSeek
.local
module is split into two: [rocket::local::asynchronous
][rocket::local::asynchronous] and[
rocket::local::blocking
][rocket::local::blocking].Try
implementation on [Outcome
][Outcome] which allowed using?
withOutcome
s. Therecommended replacement is the [
rocket::outcome::try_outcome!
][rocket::outcome::try_outcome!] macro or the variouscombinator functions on
Outcome
.Result<T, E>
implementsResponder
][Result<T, E> implements Responder] only when bothT
andE
implementResponder
. Thenew [
Debug
][Debug] wrapping responder replacesResult<T: Responder, E: Debug>
.!
type to now use [std::convert::Infallible
][std::convert::Infallible].IntoOutcome
][IntoOutcome] was overhauled to supplant methods now removed inOutcome
.IntoOutcome::into_outcome()
is nowor_error()
.IntoOutcome
is implemented for allOutcome
type aliases.Outcome::forward()
requires specifying a status code.Outcome::from()
andOutcome::from_or_forward()
were removed.Rocket::register()
][Rocket::register()] now takes a base path to scope catchers under as its first argument.ErrorKind::Collision
has been renamed to [ErrorKind::Collisions
][ErrorKind::Collisions].tls
feature is enabled.MediaType::with_params()
][MediaType::with_params()] and [ContentType::with_params()
][ContentType::with_params()] are now builder methods.content
][content] responder type names are now prefixed withRaw
.content::Plain
responder is now calledcontent::RawText
.content::Custom<T>
responder was removed in favor of [(ContentType, T)
][(ContentType, T)].CookieJar::get_private_pending()
in favor of [CookieJar::get_pending()
][CookieJar::get_pending()].local_cache!
][local_cache!] macro accepts fewer types. Use [local_cache_once!
][local_cache_once!] as appropriate.Rocket::launch()
][Rocket::launch()] allowsRocket
recovery by returning the instance after shutdown.ErrorKind::Runtime
was removed; [ErrorKind::Shutdown
][ErrorKind::Shutdown] was added.Outcome::Failure
was renamed to [Outcome::Error
][Outcome::Error].Routing and URIs
#[route(GET, path = "...")]
,path
is nowuri
:#[route(GET, uri = "...")]
./<p..>
) now match zero or more segments./<a>/<p..>
) now collides with (/<a>
), requires arank
to resolve.rocket::catcher
][rocket::catcher].rocket::route
][rocket::route].rocket::http::uri::fmt
][rocket::http::uri::fmt].T
no longer converts toOption<T>
orResult<T, _>
for [uri!
][uri!] query parameters.uri!
][uri!] requires using a wrapped value or_
.&RawStr
no longer implementsFromParam
: use&str
instead.FromParam
implementations.RawStr::url_decode()
andRawStr::url_decode_lossy()
allocate as necessary, returnCow
.RawStr::from_str()
was replaced withRawStr::new()
.Origin::segments()
was replaced withOrigin.path().segments()
.Origin::path()
andOrigin::query()
return&RawStr
instead of&str
.Route::name
is nowOption<Cow<'static, str>>
.Route::set_uri
was replaced with [Route::map_base()
][Route::map_base()].Route::uri
field is now of type [RouteUri
][RouteUri].Route::base
was removed in favor ofRoute.uri().base()
.Forward
outcomes][Route Forward outcomes] are now associated with aStatus
.FromParam
errors now forward as 422.&Host
,&Accept
,&ContentType
,IpAddr
, andSocketAddr
all forwardwith a 500.
Data and Forms
Data
now has a lifetime generic:Data<'r>
.Data::open()
][Data::open()] indelibly requires a data limit.FromDataSimple
. Use [FromData
][FromData] and [local_cache!
][local_cache!] or [local_cache_once!
][local_cache_once!].DataStream
][DataStream] APIs require limits and return [Capped<T>
][Capped] types.rocket::request
to [rocket::form
][rocket::form].FromQuery
. Dynamic query parameters (#[get("/?<param>")]
) use [FromForm
][FromForm] instead.FromFormValue
with [FromFormField
][FromFormField]. AllT: FromFormField
implementFromForm
.FromFormField
][FromFormField] implementations.#[form(field = ...)]
attribute to#[field(name = ...)]
.Status
.Request Guards
Cookies
to [CookieJar
][CookieJar]. Its methods take&self
.Flash.name
toFlash.kind
,Flash.msg
toFlash.message
.Request::get_param()
withRequest::param()
.Request::get_segments()
toRequest::segments()
.Request::get_query_value()
withRequest::query_value()
.Segments::into_path_buf()
withSegments::to_path_buf()
.Segments
andQuerySegments
with [Segments<Path>
andSegments<Query>
][Segments and Segments].Flash
][Flash] constructors now takeInto<String>
instead ofAsRef<str>
.State<'_, T>
request guard is now&State<T>
.FromRequest
][FromRequest]:FromRequest<'r>
.FlashMessage
][FlashMessage]:FlashMessage<'_>
.State
reexports except [rocket::State
][rocket::State].Responders
NamedFile
torocket::fs::NamedFile
Content
withcontent::Custom
.Response::body
andResponse::body_mut
are now infallible methods.ResponseBuilder
toBuilder
.Response
body reading methods. Use methods onr.body_mut()
instead.Responder
impl
forResponse
. Prefer custom responders with#[derive(Responder)]
.Status
.response::status
][response::status] were unified to all be ofthe form
Status<R>(R)
.General Improvements
In addition to new features and changes, Rocket saw the following improvements:
General
FromForm
derive,#[route]
macros, anduri!
.#[field(name = uncased(...))]
.#[field(default = expr())]
.#[field]
attributes on struct fields.Config::ident
][Config::ident] for configuring or removing the globalServer
header.Rocket::figment()
][Rocket::figment()] and [Rocket::catchers()
][Rocket::catchers()].LocalRequest::json()
][LocalRequest::json()] and [LocalResponse::json()
][LocalResponse::json()].LocalRequest::msgpack()
][LocalRequest::msgpack()] and [LocalResponse::msgpack()
][LocalResponse::msgpack()].use m::route; routes![route]
instead of needingroutes![m::route]
.a/b/c
falls back toa/b
thena
.LocalRequest::inner_mut()
][LocalRequest::inner_mut()].LocalRequest
implementsDerefMut
toRequest
.Config
for all config parameter names.ErrorKind::Config
to represent errors in configuration at runtime.rocket::fairing::Result
type alias, returned byFairing::on_ignite()
.Rocket::mount()
now accepts a base value of any type that implementsTryInto<Origin<'_>>
.500
error catcher.Error
][Error] to not panic if a panic is already in progress.Reference
][Reference] and [Asterisk
][Asterisk] URI types.UriDisplayQuery
][UriDisplayQuery] for C-like enums.UriDisplayQuery
][UriDisplayQuery] derive now recognizes the#[field]
attribute for field renaming.Client
method builders acceptTryInto<Origin>
allowing auri!()
to be used directly.Rocket
][Rocket] is now#[must_use]
.http2
crate feature.rocket::execute()
][rocket::execute()] for executing Rocket'slaunch()
future.context!
][context!] macro to [rocket_dyn_templates
][rocket_dyn_templates] for ad-hoc template contexts.time
crate is re-exported from the crate root.FromForm
,Responder
, andUriDisplay
derives now fully support generics.serde
submodules.Shield
][Shield] HSTS preload header now includesincludeSubdomains
.write!
errors ifstdout
disappears, preventing panics.Client::terminate()
][Client::terminate()] to run graceful shutdown in testing.async
runtime, never the process.local_cache_once!
][local_cache_once!] macro for request-local storage.Rocket<Build>
are now#[must_use]
, not allRocket<P>
.FromForm
][FromForm] derive.FromForm
][FromForm] derive now collects all errors that occur.rocket_sync_db_pools
][rocket_sync_db_pools].Metadata::render()
][Metadata::render()] in [rocket_dyn_templates
][rocket_dyn_templates] for direct template rendering.cookie
secure
feature is now properly conditionally enabled.rocket_sync_db_pools
was fixed.max_blocking
][max_blocking] configuration parameter to control number of blocking threads.ip_header
][ip_header] "real IP" header configuration parameter.pool()
][pool()] method is emitted by [rocket_sync_db_pools
][rocket_sync_db_pools] for code-generated pools.&[u8]
form guard.TempFile::open()
][TempFile::open()] to streamTempFile
data.LocalRequest::identity()
][LocalRequest::identity()].Error::pretty_print()
][Error::pretty_print()] for pretty-printing errors like Rocket.String
is used as a route parameter.debug
log level.Outcome
s now includes the relevant status code.Span::mixed_site()
is used in codegen to reduce errantclippy
warnings.HTTP
http2
crate feature.const
constructor forMediaType
.RawStrBuf
][RawStrBuf], an ownedRawStr
.RawStr
][RawStr].RawStr::percent_encode()
][RawStr::percent_encode()] and [RawStr::strip()
][RawStr::strip()].Host
][Host] and [&Host
][&Host] request guards.RawStr::percent_encode_bytes()
][RawStr::percent_encode_bytes()].NODELAY
is now enabled on all connections by default.Known Media Types
image/avif
.EventStream
:text/event-stream
.Markdown
:text/markdown
.MP3
:audio/mpeg
.CBZ
:application/vnd.comicbook+zip
, extension.cbz
.CBR
:application/vnd.comicbook-rar
, extension.cbr
.RAR
:application/vnd.rar
, extension.rar
.EPUB
:application/epub+zip
, extension.epub
.OPF
:application/oebps-package+xml
, extension.opf
.XHTML
:application/xhtml+xml
, extension.xhtml
.Text
as an alias for thePlain
media type.Bytes
as an alias for theBinary
media type..mjs
as known JavaScript extension.Request
:
in socket or IP address values in [FromFormValue
].Request::rocket()
][Request::rocket()] to access the activeRocket
instance.Request::uri()
now returns an&Origin<'r>
instead of&Origin<'_>
.Request::accept()
,Request::content_type()
reflect changes toAccept
,Content-Type
.Json<T>
,MsgPack<T>
acceptT: Deserialize
, not onlyT: DeserializeOwned
.rocket_sync_db_pools
use better defaults.workers * 4
.Request::host()
][Request::host()] to retrieve the client-requested host.Response
Template::try_custom()
][Template::try_custom()] for fallible template engine customization.Template::render()
.X-DNS-Prefetch-Control
header toShield
.expires
values for private cookies.#[derive(Responder)]
.Server
header is only set if one isn't already set.Content-Length
headers are sent even for partially readBody
s.Redirect
][Redirect] now accepts aTryFrom<Reference>
, allowing fragment parts.Trait Implementations
Clone
forState
.Copy
andClone
forfairing::Info
.Debug
forRocket
andClient
.Default
forStatus
(returnsStatus::Ok
).PartialEq
,Eq
,Hash
,PartialOrd
, andOrd
forStatus
.Eq
,Hash
, andPartialEq<&str>
forOrigin
.PartialEq<Cow<'_, RawStr>>>
forRawStr
.std::error::Error
forError
.Deref
andDerefMut
forLocalRequest
(toRequest
).DerefMut
forForm
,LenientForm
.From<T>
forJson<T>
,MsgPack<T>
.TryFrom<String>
andTryFrom<&str>
forOrigin
.TryFrom<Uri>
for each of the specific URI variants.FromRequest
for&Config
.FromRequest
forIpAddr
.FromParam
forPathBuf
FromParam
,FromData
, andFromForm
for&str
.FromForm
forJson<T>
,MsgPack<T>
.FromFormField
forCow
andCapped<Cow>>
Responder
fortokio::fs::File
.Responder
for(ContentType, R) where R: Responder
.Responder
for(Status, R) where R: Responder
which overridesR
's status.Responder
forstd::io::Error
(behaves asDebug<std::io::Error>
).Responder
forEither<T, E>
, equivalently toResult<T, E>
.Serialize
forFlash
.Serialize
,Deserialize
,UriDisplay
andFromUriParam
foruuid::Uuid
Serialize
,Deserialize
forRawStr
.Serialize
,Deserialize
for all URI types.Responder
forArc<T>
,Box<T>
whereT: Responder
.Serialize
andDeserialize
for [Method
][Method].Eq
for [MediaType
][MediaType] and [ContentType
][ContentType].Responder
forBox<T: Responder + Sized>
.FromForm
forArc<T>
.Fairing
forArc<dyn Fairing>
.Serialize
andDeserialize
forStatus
.Dependency Changes
serde
was introduced (1.0
).futures
was introduced (0.3
).binascii
was introduced (0.1
).ref-cast
was introduced (1.0
).atomic
was introduced (0.5
).parking_lot
was introduced (0.11
).ubtye
was introduced (0.10
).figment
was introduced (0.10
).rand
was introduced (0.8
).either
was introduced (1.0
).pin-project-lite
was introduced (0.2
).indexmap
was introduced (2.0
).tempfile
was introduced (3.0
).async-trait
was introduced (0.1
).async-stream
was introduced (0.3
).multer
was introduced (2.0
).tokio
was introduced (1.6.1
).tokio-util
was introduced (0.6
).tokio-stream
was introduced (0.1.6
).bytes
was introduced (1.0
).normpath
was introduced (1
).state
was updated to0.6
.rmp-serde
was updated to0.15
.uuid
was updated to0.8
.tera
was updated to1.10
.postgres
was updated to0.19
.rusqlite
was updated to0.25
.r2d2_sqlite
was updated to0.18
.time
was updated to0.3
.handlebars
was updated to4.0
.memcache
was updated to0.16
.rustls
was updated to0.21
.tokio-rustls
was updated to0.24
.syn
was updated to2
.diesel
was updated to2.0
.sqlx
was updated to0.7
.notify
was updated to6
.criterion
was updated to0.4
.cookie
was updated to0.18
.yansi
was updated to1.0
.atty
was removed.Infrastructure
The following changes were made to the project's infrastructure:
use
statements to examples in the guide.criterion
and datasets extracted from real-world projects.Cargo.toml
files.test.sh
for a+
flag (e.g.+stable
) to pass tocargo
.test.sh
for extra flags to be passed on tocargo
.resolver = 2
.Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.