HTTP::Promise::Headers::Accept - Accept Header Field
use HTTP::Promise::Headers::Accept; my $ac = HTTP::Promise::Headers::Accept->new || die( HTTP::Promise::Headers::Accept->error, "\n" ); my $ac = HTTP::Promise::Headers::Accept->new( 'text/html, application/json, application/xml;q=0.9, */*;q=0.8' ) || die( HTTP::Promise::Headers::Accept->error, "\n" ); $ac->add( 'text/html' ); $ac->add( 'application/json' => 0.7 ); $h->accept( $ac->as_string ); Accept: text/html, application/json;q=0.7 # or $h->accept( "$ac" ); my $qv_elements = $ac->elements; my $obj = $ac->get( 'text/html' ); # change the weight $obj->value( 0.3 ); $ac->remove( 'text/html' ); my $sorted_objects = $ac->sort; my $asc_sorted = $ac->sort(1); # Returns a Module::Generic::Array object my $ok = $ac->match( [qw( application/json text/html )] );
v0.1.0
The following description is taken from Mozilla documentation.
Accept: image/* Accept: text/html Accept: */* Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8
See rfc7231 section 5.3.2 and rfc7231, section 5.3.5
Provided with a mime type and a quality weight (q-value), and this will push a new HTTP::Promise::Field::QualityValue object to the stack of elements.
HTTP::Promise::Field::QualityValue
Returns a string representation of the Accept object.
Accept
Retrieve an array object of HTTP::Promise::Field::QualityValue objects.
Provided with a mime type and this returns its HTTP::Promise::Field::QualityValue object entry, if any. If nothing corresponding was found, it returns an empty string (false, but not undef)
undef
Provided with a either an array reference of proposed values, or a string, or something that stringifies, and this will return an array object of values that match the supported one and in the order of preference.
For example, consider:
Accept: text/html;q=0.3, application/json;q=0.7; text/plain;q=0.2 # We prefer text/html first and application/json second my $ok = $ac->match( [qw( text/html application/json )] );
$ok would contain 2 entries: application/json and text/html
$ok
application/json
text/html
# Only take the first one my $mime_type = $ac->match( [qw( text/html application/json )] )->first; # or get it as a list my @ok_types = $ac->match( [qw( text/html application/json )] )->list;
Provided with a mime type and this removes its HTTP::Promise::Field::QualityValue object from the list of elements.
This returns a sorted array object of HTTP::Promise::Field::QualityValue objects, based on their weight factor. If the option reverse is provided and true, this will sort the elements in reverse order, that is in incremental order, from smallest to biggest quality factor.
reverse
For example, the following:
text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8
will be sorted as:
text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8
Jacques Deguest <jack@deguest.jp>
HTTP::Promise, HTTP::Promise::Request, HTTP::Promise::Response, HTTP::Promise::Message, HTTP::Promise::Entity, HTTP::Promise::Headers, HTTP::Promise::Body, HTTP::Promise::Body::Form, HTTP::Promise::Body::Form::Data, HTTP::Promise::Body::Form::Field, HTTP::Promise::Status, HTTP::Promise::MIME, HTTP::Promise::Parser, HTTP::Promise::IO, HTTP::Promise::Stream, HTTP::Promise::Exception
HTTP::Accept
Copyright(c) 2022 DEGUEST Pte. Ltd.
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTTP::Promise, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Promise
CPAN shell
perl -MCPAN -e shell install HTTP::Promise
For more information on module installation, please visit the detailed CPAN module installation guide.