NAME

HTTP::Promise::Headers::Generic - Generic HTTP Header Class

SYNOPSIS

    package HTTP::Promise::Header::MyHeader;
    use strict;
    use warnings;
    use parent qw( HTTP::Promise::Headers::Generic );

VERSION

    v0.1.0

DESCRIPTION

This is a generic module to be inherited by HTTP header modules. See for example: HTTP::Promise::Headers::AcceptEncoding, HTTP::Promise::Headers::AcceptLanguage, HTTP::Promise::Headers::Accept, HTTP::Promise::Headers::AltSvc, HTTP::Promise::Headers::CacheControl, HTTP::Promise::Headers::ClearSiteData, HTTP::Promise::Headers::ContentDisposition, HTTP::Promise::Headers::ContentRange, HTTP::Promise::Headers::ContentSecurityPolicy, HTTP::Promise::Headers::ContentSecurityPolicyReportOnly, HTTP::Promise::Headers::ContentType, HTTP::Promise::Headers::Cookie, HTTP::Promise::Headers::ExpectCT, HTTP::Promise::Headers::Forwarded, HTTP::Promise::Headers::Generic, HTTP::Promise::Headers::KeepAlive, HTTP::Promise::Headers::Link, HTTP::Promise::Headers::Range, HTTP::Promise::Headers::ServerTiming, HTTP::Promise::Headers::StrictTransportSecurity, HTTP::Promise::Headers::TE

METHODS

as_string

Return a string representation of this header field object.

field_name

Sets or gets the object headers field name

uri_escape_utf8

Provided with some string and this returns the URI-escaped version of this using URI::Escape::XS

value

By default and superseded by inheriting classes such as Content-Type that has more elaborate value with parameters

PRIVATE METHODS

_filename_decode

Provided with a filename, and this will decode it, if necessary, by calling "decode_filename" in HTTP::Promise::Headers

It returns in list context the decoded filename, the character-set and language used and in scalar context the decoded filename.

If the filename did not need to be decoded, it will return the filename untouched, so this is quite safe to use.

See rfc2231

_filename_encode

Provided with a filename, and an optional language, and this will encode it, if necessary, following the rfc2231

If the filename did not need to be encoded, it returns undef, so be sure to check for the return value.

See rfc2231

_hv

Sets or gets the header value object

_hv_as_string

Returns the header value object as a string, if a header value object is set, or an empty string otherwise.

_get_header_value_object

This instantiates a new header value object, passing it whatever arguments were provided, and return the new object.

_make_boundary

Returns a new boundary using Data::UUID

_new_hv

Does the same thing as "_get_header_value_object"

_new_qv_object

This instantiates a new quality value object using HTTP::Promise::Field::QualityValue, passing it whatever arguments were provided, and return the new object.

_parse_header_value

Provided with a string, and this instantiates a new header value object, by calling "new_from_header" in Module::Generic::HeaderValue passing it the string and any other arguments that were provided, and return the new object.

Upon error, this sets an error and returns undef

_parse_quality_value

Provided with a string representing a quality value, and this will parse it and return a new array object

See rfc7231, section 5.3.1

_qstring_join

Provided with a list of strings and this will ensure any special characters are escaped before returning them as one string separated by comma.

See also "_qstring_split"

_qstring_split

Provided with a string, and this will split it by comma, mindful of any special characters.

It returns an array of the parts split.

_qv_add

Provided with an element and its value, and this will instantiate a new HTTP::Promise::Field::QualityValue object and add it to the list of objects contained with the method elements (implemented in each specific header module)

_qv_as_string

This takes the list of all elements contained with the method elements (implemented in each specific header module) and returns them as a string separated by comma.

_qv_elements

Sets or gets the array object containing the list of quality values.

_qv_get

Provided with a quality value element, and this returns its corresponding object if it exists, or an empty string otherwise.

Upon error, this sets an error and returns undef

_qv_match

Provided with a string, and this returns an array object of matching quality value objects in their order of preference.

Upon error, this sets an error and returns undef

_qv_match_wildcard

This method is used to do the actual work of matching a requested value such as fr-FR or <text/html> depending on the type of header, against the ones announced in the header.

For example:

    Accept: image/*
    Accept: text/html
    Accept: */*
    Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8

    Accept-Encoding: gzip

    Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5

    Accept-Language: fr-FR, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5

This takes an "acceptable" scalar object, an array object of proposed quality-value objects, and an array object of original proposed value, and possibly an hash reference of already seen object address.

It returns an array object of matching quality-value objects.

_qv_remove

Provided with a quality-value string or object, and this will remove it from the list of elements.

It returns the element removed, or upon error, this sets an error and returns undef

_qv_sort

This takes an optional hash or hash reference of options and returns an array object of sorted element by their quality-value.

Supported options are:

  • asc

    Boolean. If true, the elements will be sorted in their ascending order, otherwise in their descending order.

_set_get_param_boolean

In retrieval mode, this takes a header value parameter, and this returns its value.

In assignment mode, this takes a header value parameter, and a value, possibly undef and assign it to the given parameter.

Upon error, this sets an error and returns undef

_set_get_param

In retrieval mode, this takes a header value parameter, and it returns its corresponding value.

In assignment mode, this takes a header value parameter, and a value and assign it.

Upon error, this sets an error and returns undef

_set_get_params

This takes a list of header-value parameter and their corresponding value and set them.

If no argument is provided, this returns the array object containing all the header-value parameters.

_set_get_properties_as_string

This takes an hash or hash reference of options and returns the header-value parameters as a regular string.

Supported options are:

  • equal

  • separator or sep

_set_get_property_boolean

This sets or gets a boolean value for the given header-value property.

It returns the boolean value for the given property.

Upon error, this sets an error and returns undef

_set_get_property_number

This sets or gets a number for the given header-value property.

It returns the number value for the given property.

Upon error, this sets an error and returns undef

_set_get_property_value

This sets or gets a value for the given header-value property.

It returns the value for the given property.

Upon error, this sets an error and returns undef

_set_get_qparam

Sets or gets a quality-value parameter. If a value is provided, any double quote found at the bginning or end are removed.

It returns the current value.

Upon error, this sets an error and returns undef

_set_get_value

This sets or gets a header main value.

For example text/html in text/html; charset=utf-8

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

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

COPYRIGHT & LICENSE

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.