tide_compress/lib.rs
1#![forbid(unsafe_code)]
2#![deny(future_incompatible)]
3#![warn(
4 meta_variable_misuse,
5 missing_debug_implementations,
6 noop_method_call,
7 rust_2018_idioms,
8 trivial_casts,
9 unused_lifetimes,
10 unused_qualifications,
11 unused_macro_rules,
12 variant_size_differences
13)]
14#![doc(test(attr(deny(future_incompatible, rust_2018_idioms, warnings))))]
15#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
16#![deny(
17 clippy::allow_attributes_without_reason,
18 clippy::default_union_representation,
19 clippy::exit,
20 clippy::lossy_float_literal,
21 clippy::mem_forget,
22 clippy::multiple_inherent_impl,
23 clippy::mut_mut,
24 clippy::ptr_as_ptr,
25 clippy::unwrap_in_result,
26 clippy::unwrap_used,
27 clippy::wildcard_dependencies
28)]
29#![warn(
30 clippy::dbg_macro,
31 clippy::empty_drop,
32 clippy::fallible_impl_from,
33 clippy::inefficient_to_string,
34 clippy::macro_use_imports,
35 clippy::match_same_arms,
36 clippy::multiple_crate_versions,
37 clippy::no_effect_underscore_binding,
38 clippy::panic,
39 clippy::print_stderr,
40 clippy::print_stdout,
41 clippy::same_name_method,
42 clippy::single_char_lifetime_names,
43 clippy::string_to_string,
44 clippy::trait_duplication_in_bounds,
45 clippy::type_repetition_in_bounds,
46 clippy::unimplemented,
47 clippy::unneeded_field_pattern,
48 clippy::unseparated_literal_suffix,
49 clippy::used_underscore_binding
50)]
51
52//! Outgoing body compression middleware for the [Tide][] server framework.
53//!
54//! ```rust
55//! #[async_std::main]
56//! async fn main() {
57//! let mut app = tide::new();
58//! app.with(tide_compress::CompressMiddleware::new());
59//! }
60//! ```
61//!
62//! ## Features
63//!
64//! - Support for [Brotli][], [Gzip][], and [Deflate][] encodings, compile-time configurable through cargo feature flags.
65//! - Prioritizes Brotli if available.
66//! - Only pulls in the necessary dependencies for the desired configuration.
67//! - Defaults to Brotli & Gzip.
68//! - Also handles the `"identity"` encoding directive [as per RFC 9110][Identity].
69//! - [`Accept-Encoding`][] header checking including priority.
70//! - Minimum body size threshold (Default: 1024 bytes, configurable).
71//! - Does not compress responses with a [`Cache-Control: no-transform`][] header.
72//! - Sets the [`Vary`][] header.
73//! - Checks the [`Content-Type`][] header (MIME).
74//! - Checks against [jshttp's comprehensive database][jshttp mime-db], which is compiled to a [perfect hash function][].
75//! - The database can be regenerated in the crate's repository by running `cargo run generate-database`.
76//! - If not in the database, checks against a regular expression.
77//! - Default: `^text/|\+(?:json|text|xml)$` (case insensitive).
78//! - Fully override-able to any custom [`Regex`][], with `None` as an option.
79//! - Functionality can be excluded in crate features if the `regex` crate poses build issues.
80//!
81//! [`Accept-Encoding`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
82//! [`Cache-Control: no-transform`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
83//! [`Content-Type`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
84//! [`Regex`]: https://docs.rs/regex/1/regex/struct.Regex.html
85//! [`Vary`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary
86//! [jshttp mime-db]: https://github.com/jshttp/mime-db/blob/master/db.json
87//! [perfect hash function]: https://github.com/rust-phf/rust-phf
88//! [Brotli]: https://en.wikipedia.org/wiki/Brotli
89//! [Deflate]: https://en.wikipedia.org/wiki/Deflate
90//! [Gzip]: https://en.wikipedia.org/wiki/Gzip
91//! [Identity]: https://www.rfc-editor.org/rfc/rfc9110.html#name-accept-encoding
92//! [Tide]: https://github.com/http-rs/tide
93
94#[cfg(feature = "db-check")]
95mod codegen_database;
96
97mod middleware;
98
99pub use middleware::{CompressMiddleware, CompressMiddlewareBuilder};