vary-header
Append field names to an HTTP Vary header — correctly. De-duplicates
case-insensitively, preserves existing casing, validates field-name tokens, and
collapses to * when the header (or a field) is *. A faithful Rust port of the
vary npm package (used by cors,
compression, …). Zero dependencies and #![no_std].
use append;
assert_eq!;
assert_eq!;
assert_eq!; // already present (case-insensitive)
assert_eq!; // varies on everything
Why vary-header?
Setting Vary by hand — res.headers["vary"] += ", Origin" — easily produces
duplicates, wrong casing, or a value that should have been *. This is the canonical
algorithm (the one behind Express's cors and compression middleware), ported
faithfully so you get the same result.
The crate is named
vary-headerbecause thevaryname on crates.io is taken by an unrelated package.
[]
= "0.1"
API
| Item | Purpose |
|---|---|
append(header, field) |
Append a field (or comma-separated list) to a Vary value |
append_fields(header, &[field, …]) |
Append already-separated literal field names |
VaryError |
FieldRequired / InvalidFieldName |
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of Apache-2.0 or MIT at your option.