The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Dancer::Headers - Wrapper to handle request headers

SYNOPSYS

    use Dancer::Headers;

    # $headers may be either an ARRAY of key-value pairs, or 
    # an HTTP::Headers object.
    $dh = Dancer::Headers->new(headers => $headers);

    # $dh is now a normalized object, which lets the user do:
    # $dh->get('Some-Header');

DESCRIPTION

This class implements a wrapper that can provide a common interface to access headers, no matter what their origin is.

When the Dancer application is ran under Plack, the headers are accessed via Plack::Request, which returns a HTTP::Headers object. When under the standalone server (powered by HTTP::Server::Simple::PSGI, the headers are sent as an array.

Dancer::Headers takes care of normalizing those two kind of data structure into a singe object.

METHODS

get($header)

Returns the value of the given $header.

ARRAY references are stored for headers with multiple values. When get is called in a scalar context on such entries, it returns the first value stored, if called in list context, it returns all the values.

    $headers = Dancer::Headers->new([foo => 1, foo => 2]);
    my $first = $headers->get('foo'); # 1
    my @all   = $headers->get('foo'); # (1, 2)

get_all()

Returns the whole normalized HASH reference.

AUTHORS

This module as been writen by Alexis Sukrieh

SEE ALSO

Dancer