Code Monkey home page Code Monkey logo

http-accept's Introduction

Build Packagist PHP Version Packagist Version License

http-accept parser

http-accept is a PHP parser designed to handle HTTP headers related to content negotiation. These headers include Accept, Accept-Language, Accept-Encoding, and Content-Type. The library provides parser classes for each of these headers, making it easy to extract the relevant information from incoming HTTP requests.

Installation

You can install this library using composer.

composer require asispts/http-accept

Usage

To parse the different headers, use the corresponding parser class.

Parse Content-Type

$contentType = (new ContentTypeParser())->parse($source);

Parse HTTP Accept

$types = (new AcceptParser())->parse($source);

Parse Accept-Language

$languages = (new AcceptLanguageParser())->parse($source);

Parse Accept-Encoding

$encodings = (new AcceptEncodingParser())->parse($source);

Contributing

All forms of contributions are welcome, including bug reports, feature requests, and pull requests. If you plan to make major changes, please open an issue first to discuss what you would like to change.

License

Released under Apache-2.0 License. See LICENSE file for more details.

http-accept's People

Contributors

asispts avatar pattisahusiwa avatar tobyzerner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tobyzerner

http-accept's Issues

Extract basic HTTP header parsing functionality

I need to parse the Content-Type header with parameters. Using the Accept parser works fine, but it feels a bit wrong, since Content-Type has only a subset of the semantics (can only have one, and no q parameter or scoring).

I wonder if you'd be open to a slight refactor to extract the basic parsing functionality into a separate class perhaps, and build the more specialised Accept parsing on top of that?

Parse media type parameters

Currently parameters are not parsed into key/value pairs, they're just stored as an array of strings:

$mediaList = (new AcceptParser())->parse('*/*; one=value; two=value');
print_r($mediaList->preferedMedia(0)->parameters());
Array
(
    [0] => one=value,
    [1] => two=value
)

Is there any reason they're not parsed into key/value pairs, ie:

Array
(
    [one] => value,
    [two] => value
)

Replace coding standard

Package pattisahusiwa/coding-standard is abandoned, you should avoid using it. Use asispts/ptscs instead.

Package pattisahusiwa/coding-standard has been replaced by asispts/ptscs. However, asispts/ptscs requires PHP version 7.2 or higher.

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.