HTTP-Accept

Parse the HTTP header 'Accept'


License
Artistic-2.0

Documentation

Build Status Kwalitee status GitHub issues

NAME

HTTP::Accept - Parse the HTTP header 'Accept'

VERSION

version 0.03

SYNOPSIS

use HTTP::Accept;

my $header         = 'text/html, application/json;q=0.5';
my $accept_header  = HTTP::Accept->new( $header );

# returns text/html
my $use_accept     = $accept_header->match( qw(text/html application/json) );

ATTRIBUTES

string

The header string as passed to new.

values

The given media types in the prioritized order.

Header                            | Values
----------------------------------+----------------------------
text/html, application/json;q=0.5 | text/html, application/json
application/json;q=0.5, text/html | text/html, application/*
application/*;q=0.5, text/html    | text/html, application/*
*/*                               | */*

METHODS

new

my $header         = 'text/html, application/json;q=0.5';
my $accept_header  = HTTP::Accept->new( $header );

match

# header: 'text/html, application/json;q=0.5'
my $accept = $accept_header->match('text/html');                     # text/html
my $accept = $accept_header->match('application/json');              # application/json
my $accept = $accept_header->match('application/json', 'text/html'); # text/html
my $accept = $accept_header->match();                                # empty string
my $accept = $accept_header->match(undef);                           # empty string
my $accept = $accept_header->match('image/png');                     # empty string

Development

The distribution is contained in a Git repository, so simply clone the repository

$ git clone git://github.com/reneeb/HTTP-Accept.git

and change into the newly-created directory.

$ cd HTTP-Accept

The project uses Dist::Zilla to build the distribution, hence this will need to be installed before continuing:

$ cpanm Dist::Zilla

To install the required prequisite packages, run the following set of commands:

$ dzil authordeps --missing | cpanm
$ dzil listdeps --author --missing | cpanm

The distribution can be tested like so:

$ dzil test

To run the full set of tests (including author and release-process tests), add the --author and --release options:

$ dzil test --author --release

AUTHOR

Renee Baecker reneeb@cpan.org

COPYRIGHT AND LICENSE

This software is Copyright (c) 2018 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)