HTTP::Accept - Parse the HTTP header 'Accept'
version 0.03
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) );
The header string as passed to new.
new
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/* */* | */*
my $header = 'text/html, application/json;q=0.5'; my $accept_header = HTTP::Accept->new( $header );
# 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
Renee Baecker <reneeb@cpan.org>
This software is Copyright (c) 2018 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install HTTP::Accept, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Accept
CPAN shell
perl -MCPAN -e shell install HTTP::Accept
For more information on module installation, please visit the detailed CPAN module installation guide.