Giter Club home page Giter Club logo

headers-accept's Introduction

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.3"

๐Ÿคธ 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!

headers-accept's People

Contributors

maxcountryman avatar mpalmer avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

mpalmer

headers-accept's Issues

"More specific override" logic not implemented

RFC9110 s12.5.1 says:

Media ranges can be overridden by more specific media ranges or specific media types. If more than one media range applies to a given type, the most specific reference has precedence.

It then goes on to give an example.

I've written a test case,based on the example in the spec, that exercises this behaviour, which currently fails:

    #[test]
    fn more_specifics() {
        let accept = Accept::from_str(
            "text/*, text/plain, text/plain;format=flowed, */*"
            )
            .unwrap();
        let mut media_types = accept.media_types();
        assert_eq!(
            media_types.next(),
            Some(&MediaTypeBuf::from_str("text/plain;format=flowed").unwrap())
        );
        assert_eq!(
            media_types.next(),
            Some(&MediaTypeBuf::from_str("text/plain").unwrap())
        );
        assert_eq!(
            media_types.next(),
            Some(&MediaTypeBuf::from_str("text/*").unwrap())
        );
        assert_eq!(
            media_types.next(),
            Some(&MediaTypeBuf::from_str("*/*").unwrap())
        );
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.