Commit Graph

35 Commits

Author SHA1 Message Date
Sergio Benitez
7adfbd5a1e New version: 0.4.8. 2021-05-18 21:18:12 -07:00
Sergio Benitez
6850f95115 Update 'base64' to 0.13'. 2021-05-18 21:10:37 -07:00
Sergio Benitez
b67bd8be90 New version: 0.4.7. 2021-02-09 17:41:40 -08:00
Sergio Benitez
b4fadae53d New version: 0.4.6. 2020-11-09 23:22:43 -08:00
Ian Jackson
c24a96308b Add support for immediate chunk flushing, SSE.
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.)
2020-10-29 23:37:36 -07:00
Sergio Benitez
4683407f59 New version: 0.4.5. 2020-05-30 14:29:06 -07:00
Sergio Benitez
7739c0e977 Update 'base64' to '0.12'. 2020-05-29 01:53:06 -07:00
Sergio Benitez
807e3b8d85 New version: 0.4.4. 2020-03-09 02:17:21 -07:00
Sergio Benitez
b3d65b0ad2 New version: 0.4.3. 2020-02-29 18:19:02 -08:00
Sergio Benitez
2d4dc5ae58 New version: 0.4.2. 2019-06-28 17:50:57 -07:00
Sergio Benitez
2d4eec8f7e Update 'version_check' to 0.9. 2019-06-28 12:17:28 -07:00
Sergio Benitez
f1f09f17ca New version: 0.4.1. 2019-05-11 16:51:38 -07:00
Richard Petrie
2cb35e2544 Replace deprecated 'isatty' with 'atty'. 2019-05-10 19:50:58 -07:00
Sergio Benitez
a4dcb0cf4c New version: 0.4.0. 2018-12-06 09:19:11 -08:00
Sergio Benitez
90a6749313 New version: 0.4.0-rc.2. 2018-11-30 21:00:18 -08:00
Sergio Benitez
7919ceac39 Strip dev-dependencies more reliably. 2018-11-30 20:58:29 -08:00
Sergio Benitez
5ec21d5ba0 Update dependencies to published versions. 2018-11-30 09:00:16 -08:00
Sergio Benitez
abb434f228 Stop using white for legible logging everywhere.
Prior to this change, Rocket emitted "white" text in much of its logging
output. On terminals with light backgrounds, the text was nearly
illegible. This PR stops using white coloring altogether, opting instead
to use the terminal's default color albeit with bold styling. On dark
terminals, this will likely be a light color, and on light terminals,
this will likely be a dark color. The end result is that Rocket's
logging output should be readable everywhere.

Resolves #639.
2018-11-19 02:11:38 -08:00
Sergio Benitez
76c830a467 Update 'base64', 'crossbeam', 'rand' dependencies. 2018-11-18 03:47:12 -08:00
Sergio Benitez
4224419e63 Reduce 'cfg' usage for 'private-cookies' feature. 2018-11-08 23:56:15 -08:00
Linus Unnebäck
53758c6dd7 Introduce the 'private-cookies' feature. 2018-11-08 23:38:18 -08:00
Sergio Benitez
4dbd87a36f New version: 0.4.0-rc.1. 2018-10-31 14:35:30 -07:00
Sergio Benitez
7b2b6aba81 Use published version of 'pear'. 2018-10-28 20:17:44 -07:00
Sergio Benitez
556206e8b3 Version all URLs to 'rocket.rs'. 2018-10-26 21:20:12 -07:00
Sergio Benitez
9ef0b731c8 Rename 'codegen_next' to 'codegen'. 2018-10-22 00:01:41 -07:00
Sergio Benitez
05eee14d90 Update pear to latest revision. 2018-10-14 23:49:02 -07:00
Sergio Benitez
8b1e93192e Version documentation. 2018-10-09 04:31:09 -07:00
Sergio Benitez
2839aca8ce Update features for latest nightly. 2018-10-09 04:31:09 -07:00
Sergio Benitez
360b0e80b0 Port all codegen tests to codegen_next. 2018-10-09 04:31:08 -07:00
Sergio Benitez
633d37bc97 Fix invalid TOML test for updated 'toml' dependency. 2018-09-25 19:41:59 -07:00
Sergio Benitez
19d8569cdb Update core, codegen for 2018-07-16 nightly. 2018-07-17 14:06:32 -07:00
Sergio Benitez
df7111143e Split the 'http' module into its own 'rocket_http' crate. 2018-06-07 15:34:47 +02:00
Sergio Benitez
900e716ea6 Update to Pear 0.1. 2018-06-04 18:06:08 +02:00
Sergio Benitez
1e8e4cc553 Fix Cargo.toml path to README. 2018-06-03 19:39:32 +02:00
Sergio Benitez
f171dc9d09 Reorganize repository.
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'.
2018-06-03 18:44:38 +02:00