Rocket/examples
Sergio Benitez 7cc818cd85 Introduce dynamic TLS resolvers.
This commit introduces the ability to dynamically select a TLS
configuration based on the client's TLS hello via the new `Resolver`
trait. In support of this, it also makes the following changes:

  * Added `Authority::set_port()`.
  * `UdsListener` is now `UnixListener`.
  * `Bindable` removed in favor of new `Bind`.
  * All built-in listeners now implement `Bind<&Rocket>`.
  * `Connection` requires `AsyncRead + AsyncWrite`.
  * The `Debug` impl for `Endpoint` displays the underlying address.
  * `Listener` must be `Sized`.
  * The TLS listener was moved to `tls::TlsListener`.
  * The preview `quic` listener no longer implements `Listener`.
  * Added `TlsConfig::server_config()`.
  * Added `race` future helpers.
  * Added `Rocket::launch_with()`, `Rocket::bind_launch()`.
  * Added a default `client.pem` to the TLS example.
  * Various unnecessary listener `Config` structures removed.

In addition, the testbench was revamped to support more scenarios. This
resulted in the following issues being found and fixed:

  * Fix an issue where the logger would ignore color requests.
  * Clarified docs for `mtls::Certificate` guard.
  * Improved error messages on listener misconfiguration.

Resolves #2730.
Resolves #2363.
Closes #2748.
Closes #2683.
Closes #2577.
2024-04-16 23:50:28 -07:00
..
chat Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
config Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
cookies Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
databases Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
error-handling Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
fairings Migrate Rocket to Rust 2021 edition. 2022-04-19 18:35:38 -07:00
forms Qualm various emerging unused warnings. 2023-11-01 01:16:28 -05:00
hello Update to hyper 1. Enable custom + unix listeners. 2024-01-29 22:38:55 -08:00
manual-routing Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
pastebin Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
responders Fix SSE heartbeat so it never interrupts events. 2022-04-27 13:59:03 -07:00
serialization Improve forwarding status code precision. 2023-10-31 18:44:37 -05:00
state Update dependencies and fix nightly warnings. 2024-04-11 18:09:21 -07:00
static-files Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
templating Update 'handlebars' to v5.1. 2024-01-17 21:41:25 -08:00
testing Migrate Rocket to Rust 2021 edition. 2022-04-19 18:35:38 -07:00
tls Introduce dynamic TLS resolvers. 2024-04-16 23:50:28 -07:00
todo Clean up codebase: fix reasonable clippy warnings. 2024-03-20 00:47:38 -07:00
upgrade Update to hyper 1. Enable custom + unix listeners. 2024-01-29 22:38:55 -08:00
Cargo.toml Use 'resolver = 2' across workspaces. 2023-06-09 16:46:58 -07:00
README.md Add 'upgrade' example with WebSocket support. 2023-03-29 17:07:01 -07:00

README.md

Rocket Examples

This directory contains projects showcasing Rocket's features.

Applications

  • pastebin

    A simple, API-only pastebin application, similar to https://paste.rs. Stores pastes locally on the file system. Implements a custom parameter guard, PasteId, to parse and validate paste identifiers.

  • todo

    A todo app with a web UI to add, delete, and mark/unmark items. Uses a SQLite database driven by diesel. Runs migrations automatically at start-up. Uses tera to render templates.

  • chat

    A real-time, multi-room chat application using Server-Sent Events (SSE) and JavaScript's EventSource. Supports automatic reconnection with exponential backoff and live connection status.

Feature Examples

  • config - Illustrates how to extract values from a Rocket Figment, how to store and retrieve an application specific configuration in managed state using AdHoc::config(), and how to set configuration values in Rocket.toml.

  • cookies - Uses cookies to create a client-side message box. Uses private cookies for a session-based authentication.

  • databases - Implements a CRUD-like "blog" JSON API backed by a SQLite database driven by each of sqlx, diesel, and rusqlite. Runs migrations automatically for the former two drivers. Uses contrib database support for all drivers (rocket_db_pools for the first; rocket_sync_db_pools for the other latter two).

  • error-handling - Exhibits the use of scoped catchers; contains commented out lines that will cause a launch-time error with code to custom-display the error.

  • fairings - Exemplifies creating a custom Counter fairing and using AdHoc fairings.

  • forms - Showcases all of Rocket's form support features including multipart file uploads, ad-hoc validations, field renaming, and use of form context for staged forms.

  • hello - Basic example of Rocket's core features: route declaration with path and query parameters, both simple and compound, mounting, launching, testing, and returning simple responses. Also showcases using UTF-8 in route declarations and responses.

  • manual-routing - An example eschewing Rocket's codegen in favor of manual routing. This should be seen as last-ditch effort, much like unsafe in Rust, as manual routing also eschews many of Rocket's automatic web security guarantees.

  • responders - Illustrates the use of many of Rocket's built-in responders: Stream, Redirect, File, NamedFile, content for manually setting Content-Types, and Either. In the process, showcases using TempFile for raw uploads. Also illustrates the creation of a custom, derived Responder.

  • serialization - Showcases JSON and MessagePack (de)serialization support by implementing a CRUD-like message API in JSON and a simply read/echo API in MessagePack. Showcases UUID parsing support.

  • state - Illustrates the use of request-local state and managed state. Uses request-local state to cache "expensive" per-request operations. Uses managed state to implement a simple index hit counter. Also uses managed state to store, retrieve, and push/pop from a concurrent queue.

  • static-files - Uses FileServer to serve static files. Also creates a second manual yet safe version.

  • templating - Illustrates using contrib templates support with identical examples for handlebars and tera.

  • testing - Uses Rocket's local libraries to test an application. Showcases necessary use of the async Client. Note that all examples contains tests, themselves serving as examples for how to test Rocket applications.

  • tls - Illustrates configuring TLS with a variety of key pair kinds.

  • upgrade - Uses the connection upgrade API to implement WebSocket support using tungstenite.