This commit makes it possible to build, document, and test Rocket v0.4.
The main changes are:
* A `Cargo.lock` was added that includes references to yanked deps.
* The `tls` feature isn't tested as `ring` fails to build.
* The site guide was moved to `docs/guide`.
* The `site/` directory was removed.
Problem:
To support Server-Side Events (SSE, aka JS EventSource) it is
necessary for the server to keep open an HTTP request and dribble out
data (the event stream) as it is generated.
Currently, Rocket handles this poorly. It likes to fill in complete
chunks. Also there is no way to force a flush of the underlying
stream: in particular, there is a BufWriter underneath hyper. hyper
would honour a flush request, but there is no way to send one.
Options:
Ideally the code which is producing the data would be able to
explicitly designate when a flush should occur. Certainly it would
not be acceptable to flush all the time for all readers.
1. Invent a new kind of Body (UnbufferedChunked) which translates the
data from each Read::read() call into a single call to the stream
write, and which always flushes. This would be a seriously invasive
change. And it would mean that SSE systems with fast event streams
might work poorly.
2. Invent a new kind of Body which doesn't use Read at all, and
instead has a more sophisticated API. This would be super-invasive
and heavyweight.
3. Find a way to encode the necessary information in the Read trait
protocol.
Chosen solution:
It turns out that option 3 is quite easy. The read() call can return
an io::Error. There are at least some errors that clearly ought not
to occur here. An obvious one is ErrorKind::WouldBlock.
Rocket expects the reader to block. WouldBlock is only applicable to
nonblocking objects. And indeed the reader will generally want to
return it (once) when it is about to block.
We have the Stream treat io::Error with ErrorKind::WouldBlock, from
its reader, as a request to flush. There are two effects: we stop
trying to accumulate a full chunk, and we issue a flush call to the
underlying writer (which, eventually, makes it all the way down into
hyper and BufWriter).
Implementation:
We provide a method ReadExt::read_max_wfs which is like read_max but
which handles the WouldBlock case specially. It tells its caller
whether a flush was wanted.
This is implemented by adding a new code to read_max_internal. with a
boolean to control it. This seemed better than inventing a trait or
something. (The other read_max call site is reading http headers in
data.rs, and I think it wants to tread WouldBlock as an error.)
Risks and downsides:
Obviously this ad-hoc extension to the Read protocol is not
particularly pretty. At least, people who aren't doing SSE (or
similar) won't need it and can ignore it.
If for some reason the data source is actually nonblocking, this new
arrangement would spin, rather than calling the situation a fatal
error. This possibility seems fairly remote, in production settings
at least. To migitate this it might be possible for the loop in
Rocket::issue_response to bomb out if it notices it is sending lots of
consecutive empty chunks.
It is possible that async Rocket will want to take a different
approach entirely. But it will definitely need to solve this problem
somehow, and naively it seems like the obvious transformation to eg
the Tokio read trait would have the same API limitation and admit the
same solution. (Having a flush occur every time the body stream
future returns Pending would not be good for performance, I think.)
Every code example is now fully runnable and testable. As a result, all
examples are now tested and include imports. Relevant imports are shown
by default. Code examples can be expanded to show all imports.
Fixes#432.
The directory structure has changed to better isolate crates serving
core and contrib. The new directory structure is:
contrib/
lib/ - the contrib library
core/
lib/ - the core Rocket library
codegen/ - the "compile extension" codegen library
codegen_next/ - the new proc-macro library
examples/ - unchanged
scripts/ - unchanged
site/ - unchanged
This commit also removes the following files:
appveyor.yml - AppVeyor (Rust on Windows) is far too spotty for use
rustfmt.toml - rustfmt is, unfortunately, not mature enough for use
Finally, all example Cargo crates were marked with 'publish = false'.
The 'codegen_next' crate will eventually be renamed 'codegen'. It
contains procedural macros written with the upcoming 'proc_macro' APIs,
which will eventually be stabilized. All compiler extensions in the
present 'codegen' crate will be rewritten as procedural macros and moved
to the 'codegen_next' crate.
At present, macros from 'codegen_next' are exported from the core
`rocket` crate automatically. In the future, we may wish to feature-gate
this export to allow using Rocket's core without codegen.
Resolves#16.
The '2018-01-12' nightly release includes a commit that reverts the
change that broke 'ring', un-breaking 'ring', and thus un-breaking
Rocket. As a result, the '[patch]' workaround is no longer required.
Rocket is back on the latest nightly!
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>`.
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.
This commit includes the following additions:
* A `session` example was added.
* `Config::take_session_key` was removed.
* If a `session_key` is not supplied, one is automatically generated.
* The `Session` type implements signed, encrypted sessions.
* A `Session` can be retrieved via its request guard.
This commit includes the following important API changes:
* The `form` route parameter has been removed.
* The `data` route parameter has been added.
* Forms are not handled via the `data` parameter and `Form` type.
* Removed the `data` parameter from `Request`.
* Added `FromData` conversion trate and default implementation.
* Added `DataOutcome` enum, which is the return type of `from_data`.
* 'FromData' is now used to automatically derive the `data` parameter.
* Moved `form` into `request` module.
* Removed `Failure::new` in favor of direct value construction.
This commit includes the following important package additions:
* Added a 'raw_upload' example.
* `manual_routes` example uses `Data` parameter.
* Now building and running tests with `--all-features` flag.
* All exmaples have been updated to latest API.
* Now using upstream Tera.
This commit includes the following important fixes:
* Any valid ident is now allowed in single-parameter route parameters.
* Lifetimes are now properly stripped in code generation.
* `FromForm` derive now works on empty structs.
Remove form_items function in favor of FormItems iterator.
Add specialized `bool` implementation of FromFormValue.
Add `&str` implementation of FromFormValue for debugging.
Here's what works so far:
* The `route` decorator checks its inputs correctly. There's a nice utility
for doing this, and it's working quite well at the moment.
* The `route` decorator emits a `route_fn` and a `route_struct`. The `routes`
* macro prepends the path terminator with the route struct prefix. The
* `Rocket` library can read mount information (though not act on it properly
just yet) and launch a server using Hyper.