NAME
Azure::SDK::Core::Headers - case-insensitive HTTP header collection
SYNOPSIS
use Azure::SDK::Core::Headers;
my $headers = Azure::SDK::Core::Headers->new(
headers => { 'Content-Type' => 'application/xml' },
);
$headers->set( 'x-ms-version' => '2025-11-05' );
# "application/xml"
$headers->get('CONTENT-TYPE');
# "gzip, deflate"
$headers->set( 'Accept-Encoding' => [ 'gzip', 'deflate' ] )->get('accept-encoding');
DESCRIPTION
A small collection type used by Azure::SDK::Core::Request and Azure::SDK::Core::Response. Names are stored lowercased and matched case-insensitively, because HTTP field names are case-insensitive and Azure is inconsistent about which case it sends (ETag in a response header, x-ms-request-id alongside it).
A header may hold several values. They are stored as a list and joined with ", " on retrieval, which is the RFC 9110 rule for combining repeated fields. Values are always stringified, so a number or an object with overloaded stringification is stored as the text that will go on the wire.
Field names and values are validated
set requires a non-empty RFC field-name token, so spaces, separators such as :, and control characters cannot reach the transport. It also croaks when any value contains a C0 control character other than horizontal tab, or DEL. This includes carriage return, line feed, and NUL. Header fields are terminated by CRLF, so an embedded newline would let a caller inject additional headers or split the request (CWE-113). The value check covers every value in a list, not just the first, and both checks run on construction and later assignment.
CONSTRUCTOR
new
Named parameters:
headers-
Optional hashref of initial headers. Defaults to an empty hashref. Each pair is passed through
set, so the same validation and normalization apply.
METHODS
get
my $value = $headers->get($name);
Returns the value for $name, matched case-insensitively, or undef when the header is not present. Multiple values are joined with ", ".
set
$headers = $headers->set( $name => $value );
$headers = $headers->set( $name => \@values );
Stores a header, replacing any existing value. Accepts a single value or an arrayref of values; undef is stored as the empty string. Returns the collection so calls can be chained. Croaks on a malformed field name or a CR or LF in any value.
as_hashref
my $hash = $headers->as_hashref;
Returns a plain hashref of the lowercased header names and their joined values, suitable for handing to a transport.