5 releases

0.1.4 Sep 14, 2024
0.1.3 May 6, 2024
0.1.2 May 1, 2024
0.1.1 Apr 29, 2024
0.1.0 Apr 25, 2024

#504 in Network programming

Download history 848/week @ 2024-08-23 787/week @ 2024-08-30 696/week @ 2024-09-06 1257/week @ 2024-09-13 1262/week @ 2024-09-20 2097/week @ 2024-09-27 1805/week @ 2024-10-04 1470/week @ 2024-10-11 2071/week @ 2024-10-18 1817/week @ 2024-10-25 1502/week @ 2024-11-01 1462/week @ 2024-11-08 1519/week @ 2024-11-15 1904/week @ 2024-11-22 1097/week @ 2024-11-29 1058/week @ 2024-12-06

5,788 downloads per month
Used in tower-image-xform

MIT license

30KB
344 lines

headers-accept

🤝 The missing `Accept` implementation for `headers::Header`

🎨 Overview

This crate provides an implementation of headers::Header for Accept.

While other crates exist, they either rely on stagnant crates like mime (headers-accept uses mediatype instead) or deviate from RFC 9110 (by imposing onerous sort logic) or both.

This crate aims to solve these problems while adhereing to the spec outlined in section 12.5.1.

📦 Install

To use the crate in your project, add the following to your Cargo.toml file:

[dependencies]
headers-accept = "0.1.4"

🤸 Usage

Example

use std::str::FromStr;

use headers_accept::Accept;
use mediatype::MediaTypeBuf;

let accept = Accept::from_str("audio/*; q=0.2, audio/basic").unwrap();
let mut media_types = accept.media_types();
assert_eq!(
    media_types.next(),
    Some(&MediaTypeBuf::from_str("audio/basic").unwrap())
);
assert_eq!(
    media_types.next(),
    Some(&MediaTypeBuf::from_str("audio/*; q=0.2").unwrap())
);
assert_eq!(media_types.next(), None);

🦺 Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

👯 Contributing

We appreciate all kinds of contributions, thank you!

Dependencies

~1MB
~12K SLoC