https://github.com/maxcountryman/headers-accept
🤝 The missing `Accept` implementation for `headers::Header`.
https://github.com/maxcountryman/headers-accept
accept content-negotiation headers
Last synced: 12 months ago
JSON representation
🤝 The missing `Accept` implementation for `headers::Header`.
- Host: GitHub
- URL: https://github.com/maxcountryman/headers-accept
- Owner: maxcountryman
- License: mit
- Created: 2024-04-25T21:22:34.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-14T22:05:17.000Z (over 1 year ago)
- Last Synced: 2025-04-23T05:15:45.313Z (12 months ago)
- Topics: accept, content-negotiation, headers
- Language: Rust
- Homepage:
- Size: 22.5 KB
- Stars: 11
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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](https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.1).
## 📦 Install
To use the crate in your project, add the following to your `Cargo.toml` file:
```toml
[dependencies]
headers-accept = "0.1.4"
```
## 🤸 Usage
### Example
```rust
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!