vary-header 0.1.0

Append field names to an HTTP Vary header correctly (dedup, case-insensitive, '*' handling). A faithful port of the vary npm package. Zero dependencies, no_std.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented3 out of 4 items with examples
  • Size
  • Source code size: 27.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 101.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/vary-header
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

vary-header

All Contributors

Crates.io Documentation CI License

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 vary_header::append;

assert_eq!(append("", "Accept").unwrap(), "Accept");
assert_eq!(append("Accept", "Accept-Encoding").unwrap(), "Accept, Accept-Encoding");
assert_eq!(append("Accept", "accept").unwrap(), "Accept"); // already present (case-insensitive)
assert_eq!(append("Accept", "*").unwrap(), "*");           // 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-header because the vary name on crates.io is taken by an unrelated package.

[dependencies]
vary-header = "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.