| 1 | package Mojo::Headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 31 | ▶ | use Mojo::Base -base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use Carp qw(croak); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 31 | ▶ | use Mojo::Util qw(header_params monkey_patch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 531 | ▶ | has max_line_size => sub { $ENV{MOJO_MAX_LINE_SIZE} || 8192 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 531 | ▶ | has max_lines => sub { $ENV{MOJO_MAX_LINES} || 100 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Common headers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 31 | my %NAMES = map { lc() => $_ } ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | qw(Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges Access-Control-Allow-Origin Allow), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | qw(Authorization Cache-Control Connection Content-Disposition Content-Encoding Content-Language Content-Length), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | qw(Content-Location Content-Range Content-Security-Policy Content-Type Cookie DNT Date ETag Expect Expires Host), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | qw(If-Modified-Since If-None-Match Last-Modified Link Location Origin Proxy-Authenticate Proxy-Authorization), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | qw(Range Sec-WebSocket-Accept Sec-WebSocket-Extensions Sec-WebSocket-Key Sec-WebSocket-Protocol), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | qw(Sec-WebSocket-Version Server Server-Timing Set-Cookie Status Strict-Transport-Security TE Trailer), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | qw(Transfer-Encoding Upgrade User-Agent Vary WWW-Authenticate) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 31 | for my $header (keys %NAMES) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1581 | my $name = $header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1581 | $name =~ y/-/_/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 943 | ▶ | monkey_patch __PACKAGE__, $name, sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expires: called CC=4 SCAR=13.9
Subroutine
last_modified: called CC=4 SCAR=13.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 943 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 943 | ▶ | $self->{headers}{$header} = [@_] and return $self if @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%6/9
@_ && (($self->{'headers'}{$header} = [@_]) && (return $self))
$self->{"headers"}{$header} = [@_] and return $self
@_ && (($self->{'headers'}{$header} = [@_]) && (return $self))
$self->{"headers"}{$header} = [@_] and return $self
MC/DC0%0/2
@_ && (($self->{'headers'}{$header} = [@_]) && (return $self))
@_
$self->{"headers"}{$header} = [@_]
MC/DC0%0/2
@_ && (($self->{'headers'}{$header} = [@_]) && (return $self))
@_
$self->{"headers"}{$header} = [@_]
Truth table33%1/3
A && B
A= @_B= $self->{"headers"}{$header} = [@_]
Truth table33%1/3
A && B
A= @_B= $self->{"headers"}{$header} = [@_]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 752 | ▶ | return undef unless my $headers = $self->{headers}{$header}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 152 | return join ', ', @$headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1581 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Hop-by-hop headers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | my @HOP_BY_HOP | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 31 | = map {lc} qw(Connection Keep-Alive Proxy-Authenticate Proxy-Authorization TE Trailer Transfer-Encoding Upgrade); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1979 | ▶ | sub add { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=5 SCAR=16.1
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1979 | my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1979 | ▶ | tr/\x0d\x0a// and croak "Invalid characters in $name header" for @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Make sure we have a normal case entry for name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1975 | my $key = lc $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1975 | ▶ | $self->{names}{$key} //= $name unless $NAMES{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"names"}{$key} //= $name
MC/DC0%0/2
$self->{"names"}{$key} //= $name
$self->{"names"}{$key}
$name
Truth table66%2/3
A //= B
A= $self->{"names"}{$key}B= $name
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1975 | push @{$self->{headers}{$key}}, @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1975 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 30 | ▶ | sub append { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append: called CC=2 SCAR=6.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 30 | my ($self, $name, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 30 | my $old = $self->header($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 30 | ▶ | return $self->header($name => defined $old ? "$old, $value" : $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 34 | ▶ | sub clone { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=3 SCAR=11.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 34 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 34 | my $clone = $self->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 34 | ▶ | %{$clone->{names}} = %{$self->{names} // {}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"names"} // {}
MC/DC100%1/1
$self->{"names"} // {}
$self->{"names"}
Truth table100%2/2
A
A= $self->{"names"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 34 | @{$clone->{headers}{$_}} = @{$self->{headers}{$_}} for keys %{$self->{headers}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 34 | return $clone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub dehop { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dehop: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | delete @{$self->{headers}}{@HOP_BY_HOP}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 28 | ▶ | sub every_header { shift->{headers}{lc shift} // [] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
every_header: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
+(shift())->{"headers"}{lc shift()} // []
MC/DC0%0/1
+(shift())->{"headers"}{lc shift()} // []
+(shift())->{"headers"}{lc shift()}
Truth table50%1/2
A
A= +(shift())->{"headers"}{lc shift()}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 103 | ▶ | sub from_hash { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_hash: called CC=4 SCAR=13.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 103 | my ($self, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Empty hash deletes all headers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 103 | ▶ | delete $self->{headers} if keys %{$hash} == 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # Merge | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 103 | for my $header (keys %$hash) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 123 | my $value = $hash->{$header}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 123 | ▶ | $self->add($header => ref $value eq 'ARRAY' ? @$value : $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 103 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 376 | ▶ | sub header { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=3 SCAR=11.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 376 | my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # Replace | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 376 | ▶ | return $self->remove($name)->add($name, @_) if @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 292 | ▶ | return undef unless my $headers = $self->{headers}{lc $name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 240 | return join ', ', @$headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1093 | ▶ | sub is_finished { (shift->{state} // '') eq 'finished' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_finished: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
+(shift())->{"state"} // ""
MC/DC0%0/1
+(shift())->{"state"} // ""
+(shift())->{"state"}
Truth table50%1/2
A
A= +(shift())->{"state"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1012 | ▶ | sub is_limit_exceeded { !!shift->{limit} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_limit_exceeded: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 539 | ▶ | sub leftovers { delete shift->{buffer} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leftovers: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 11 | ▶ | sub links { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
links: called CC=6 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 11 | my ($self, $links) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 11 | ▶ | return $self->link(join(', ', map {qq{<$links->{$_}>; rel="$_"}} sort keys %$links)) if $links; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 8 | ▶ | my $header = $self->link // ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->link // ""
MC/DC100%1/1
$self->link // ""
$self->link
Truth table100%2/2
A
A= $self->link
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | my $data = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | ▶ | while ($header =~ s/^[,\s]*<(.+?)>//) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | my $target = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 8 | (my $params, $header) = header_params $header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 8 | ▶ | $data->{$params->{rel}} //= {%$params, link => $target} if defined $params->{rel}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$$data{$params->{"rel"}} //= {%$params, "link", $target}
MC/DC100%1/1
$$data{$params->{"rel"}} //= {%$params, "link", $target}
$$data{$params->{"rel"}}
Truth table100%2/2
A
A= $$data{$params->{"rel"}}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | return $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 445 | ▶ | sub names { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
names: called CC=2 SCAR=7.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 445 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 445 | ▶ | return [map { $NAMES{$_} || $self->{names}{$_} } sort keys %{$self->{headers}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$NAMES{$_} || $self->{'names'}{$_}
MC/DC0%0/2
$NAMES{$_} || $self->{'names'}{$_}
$NAMES{$_}
$self->{'names'}{$_}
Truth table66%2/3
A || B
A= $NAMES{$_}B= $self->{'names'}{$_}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1094 | ▶ | sub parse { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=11 SCAR=24.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1094 | my ($self, $chunk) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1094 | $self->{state} = 'headers'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1094 | $self->{buffer} .= $chunk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1094 | ▶ | my $headers = $self->{cache} //= []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"cache"} //= []
MC/DC100%1/1
$self->{"cache"} //= []
$self->{"cache"}
Truth table100%2/2
A
A= $self->{"cache"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1094 | my $size = $self->max_line_size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1094 | my $lines = $self->max_lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1094 | ▶ | while ((my $len = index($self->{buffer}, "\x0a") + 1) > 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2286 | my $line = substr $self->{buffer}, 0, $len, ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2286 | chop $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2286 | ▶ | chop $line if substr($line, -1) eq "\x0d"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Check line size limit | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2286 | ▶ | if ($len > $size || @$headers >= $lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$len > $size or @$headers >= $lines
MC/DC100%2/2
$len > $size or @$headers >= $lines
$len > $size
@$headers >= $lines
Truth table100%3/3
A or B
A= $len > $sizeB= @$headers >= $lines
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | @$self{qw(state limit)} = ('finished', 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # New header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2281 | ▶ | if ($line =~ /^(\S[^:]*):\s*(.*)$/) { push @$headers, [$1, $2] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # Multi-line | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | ▶ | elsif ($line =~ s/^\s+// && @$headers) { $headers->[-1][1] .= " $line" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$line =~ s/^\s+//u and @$headers
MC/DC50%1/2
$line =~ s/^\s+//u and @$headers
$line =~ s/^\s+//u
@$headers
Truth table66%2/3
A and B
A= $line =~ s/^\s+//uB= @$headers
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Empty line | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 538 | $self->add(@$_) for @$headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 538 | @$self{qw(state cache)} = ('finished', []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 538 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Check line size limit | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 551 | ▶ | @$self{qw(state limit)} = ('finished', 1) if length $self->{buffer} > $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 551 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | sub referer { shift->referrer(@_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
referer: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | ▶ | sub referrer { shift->header(Referer => @_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
referrer: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 386 | ▶ | sub remove { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 386 | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 386 | delete $self->{headers}{lc $name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 386 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 29 | ▶ | sub to_hash { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_hash: called CC=2 SCAR=6.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 29 | my ($self, $multi) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 29 | ▶ | return {map { $_ => $self->{headers}{lc $_} } @{$self->names}} if $multi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 19 | return {map { $_ => $self->header($_) } @{$self->names}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 389 | ▶ | sub to_string { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 389 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Make sure multi-line values are formatted correctly | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 389 | my @headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 389 | for my $name (@{$self->names}) { push @headers, "$name: $_" for @{$self->{headers}{lc $name}} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 389 | return join "\x0d\x0a", @headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 31 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | =encoding utf8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | =head1 NAME | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | Mojo::Headers - HTTP headers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | =head1 SYNOPSIS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | use Mojo::Headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # Parse | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | my $headers = Mojo::Headers->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | $headers->parse("Content-Length: 42\x0d\x0a"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | $headers->parse("Content-Type: text/html\x0d\x0a\x0d\x0a"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | say $headers->content_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | say $headers->content_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # Build | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | my $headers = Mojo::Headers->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | $headers->content_length(42); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | $headers->content_type('text/plain'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | say $headers->to_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | =head1 DESCRIPTION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | L<Mojo::Headers> is a container for HTTP headers, based on L<RFC 7230|https://tools.ietf.org/html/rfc7230> and L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 7231|https://tools.ietf.org/html/rfc7231>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | =head1 ATTRIBUTES | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | L<Mojo::Headers> implements the following attributes. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | =head2 max_line_size | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | my $size = $headers->max_line_size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | $headers = $headers->max_line_size(1024); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | Maximum header line size in bytes, defaults to the value of the C<MOJO_MAX_LINE_SIZE> environment variable or C<8192> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | (8KiB). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | =head2 max_lines | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | my $num = $headers->max_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $headers = $headers->max_lines(200); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | Maximum number of header lines, defaults to the value of the C<MOJO_MAX_LINES> environment variable or C<100>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | =head1 METHODS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | L<Mojo::Headers> inherits all methods from L<Mojo::Base> and implements the following new ones. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | =head2 add | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | $headers = $headers->add(Foo => 'one value'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | $headers = $headers->add(Foo => 'first value', 'second value'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | Add header with one or more lines. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # "Vary: Accept | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # Vary: Accept-Encoding" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | $headers->add(Vary => 'Accept')->add(Vary => 'Accept-Encoding')->to_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | =head2 append | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | $headers = $headers->append(Vary => 'Accept-Encoding'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | Append value to header and flatten it if necessary. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # "Vary: Accept" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | $headers->append(Vary => 'Accept')->to_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # "Vary: Accept, Accept-Encoding" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $headers->vary('Accept')->append(Vary => 'Accept-Encoding')->to_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | =head2 clone | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | my $clone = $headers->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | Return a new L<Mojo::Headers> object cloned from these headers. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | =head2 dehop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | $headers = $headers->dehop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | Remove hop-by-hop headers that should not be retransmitted. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | =head2 every_header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | my $all = $headers->every_header('Location'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | Similar to L</"header">, but returns all headers sharing the same name as an array reference. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # Get first header value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | say $headers->every_header('Location')->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | =head2 from_hash | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | $headers = $headers->from_hash({'Cookie' => 'a=b'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | $headers = $headers->from_hash({'Cookie' => ['a=b', 'c=d']}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | $headers = $headers->from_hash({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | Parse headers from a hash reference, an empty hash removes all headers. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | =head2 header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | my $value = $headers->header('Foo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | $headers = $headers->header(Foo => 'one value'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | $headers = $headers->header(Foo => 'first value', 'second value'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | Get or replace the current header values. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | =head2 is_finished | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | my $bool = $headers->is_finished; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | Check if header parser is finished. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | =head2 is_limit_exceeded | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | my $bool = $headers->is_limit_exceeded; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | Check if headers have exceeded L</"max_line_size"> or L</"max_lines">. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | =head2 leftovers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | my $bytes = $headers->leftovers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | Get and remove leftover data from header parser. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | =head2 names | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | my $names = $headers->names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | Return an array reference with all currently defined headers. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # Names of all headers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | say for @{$headers->names}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | =head2 parse | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | $headers = $headers->parse("Content-Type: text/plain\x0d\x0a\x0d\x0a"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | Parse formatted headers. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | =head2 remove | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | $headers = $headers->remove('Foo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | Remove a header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =head2 to_hash | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | my $single = $headers->to_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | my $multi = $headers->to_hash(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | Turn headers into hash reference, array references to represent multiple headers with the same name are disabled by | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | default. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | say $headers->to_hash->{DNT}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | =head2 to_string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | my $str = $headers->to_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | Turn headers into a string, suitable for HTTP messages. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | =head1 ADDITIONAL METHODS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | Additionally, the following shortcuts are available, for accessing and manipulating commonly-used headers: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | =head2 accept | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | my $accept = $headers->accept; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | $headers = $headers->accept('application/json'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | Get or replace current header value, shortcut for the C<Accept> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | =head2 accept_charset | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | my $charset = $headers->accept_charset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | $headers = $headers->accept_charset('UTF-8'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | Get or replace current header value, shortcut for the C<Accept-Charset> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =head2 accept_encoding | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | my $encoding = $headers->accept_encoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | $headers = $headers->accept_encoding('gzip'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | Get or replace current header value, shortcut for the C<Accept-Encoding> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | =head2 accept_language | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | my $language = $headers->accept_language; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | $headers = $headers->accept_language('de, en'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | Get or replace current header value, shortcut for the C<Accept-Language> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | =head2 accept_ranges | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | my $ranges = $headers->accept_ranges; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | $headers = $headers->accept_ranges('bytes'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | Get or replace current header value, shortcut for the C<Accept-Ranges> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | =head2 access_control_allow_origin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | my $origin = $headers->access_control_allow_origin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $headers = $headers->access_control_allow_origin('*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | Get or replace current header value, shortcut for the C<Access-Control-Allow-Origin> header from L<Cross-Origin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | Resource Sharing|https://www.w3.org/TR/cors/>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | =head2 allow | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | my $allow = $headers->allow; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | $headers = $headers->allow('GET, POST'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | Get or replace current header value, shortcut for the C<Allow> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | =head2 authorization | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | my $authorization = $headers->authorization; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | $headers = $headers->authorization('Basic Zm9vOmJhcg=='); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | Get or replace current header value, shortcut for the C<Authorization> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | =head2 cache_control | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | my $cache_control = $headers->cache_control; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | $headers = $headers->cache_control('max-age=1, no-cache'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | Get or replace current header value, shortcut for the C<Cache-Control> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | =head2 connection | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | my $connection = $headers->connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | $headers = $headers->connection('close'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | Get or replace current header value, shortcut for the C<Connection> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | =head2 content_disposition | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | my $disposition = $headers->content_disposition; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | $headers = $headers->content_disposition('foo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | Get or replace current header value, shortcut for the C<Content-Disposition> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | =head2 content_encoding | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | my $encoding = $headers->content_encoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | $headers = $headers->content_encoding('gzip'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | Get or replace current header value, shortcut for the C<Content-Encoding> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | =head2 content_language | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | my $language = $headers->content_language; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | $headers = $headers->content_language('en'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | Get or replace current header value, shortcut for the C<Content-Language> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | =head2 content_length | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | my $len = $headers->content_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | $headers = $headers->content_length(4000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | Get or replace current header value, shortcut for the C<Content-Length> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | =head2 content_location | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | my $location = $headers->content_location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | $headers = $headers->content_location('http://127.0.0.1/foo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | Get or replace current header value, shortcut for the C<Content-Location> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | =head2 content_range | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | my $range = $headers->content_range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | $headers = $headers->content_range('bytes 2-8/100'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | Get or replace current header value, shortcut for the C<Content-Range> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | =head2 content_security_policy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | my $policy = $headers->content_security_policy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | $headers = $headers->content_security_policy('default-src https:'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | Get or replace current header value, shortcut for the C<Content-Security-Policy> header from L<Content Security Policy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1.0|https://www.w3.org/TR/CSP/>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | =head2 content_type | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | my $type = $headers->content_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | $headers = $headers->content_type('text/plain'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | Get or replace current header value, shortcut for the C<Content-Type> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | =head2 cookie | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | my $cookie = $headers->cookie; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | $headers = $headers->cookie('f=b'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | Get or replace current header value, shortcut for the C<Cookie> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 6265|https://tools.ietf.org/html/rfc6265>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | =head2 date | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | my $date = $headers->date; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | $headers = $headers->date('Sun, 17 Aug 2008 16:27:35 GMT'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | Get or replace current header value, shortcut for the C<Date> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | =head2 dnt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | my $dnt = $headers->dnt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | $headers = $headers->dnt(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | Get or replace current header value, shortcut for the C<DNT> (Do Not Track) header, which has no specification yet, but | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | is very commonly used. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | =head2 etag | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | my $etag = $headers->etag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | $headers = $headers->etag('"abc321"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | Get or replace current header value, shortcut for the C<ETag> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | =head2 expect | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | my $expect = $headers->expect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | $headers = $headers->expect('100-continue'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | Get or replace current header value, shortcut for the C<Expect> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | =head2 expires | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | my $expires = $headers->expires; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | $headers = $headers->expires('Thu, 01 Dec 1994 16:00:00 GMT'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | Get or replace current header value, shortcut for the C<Expires> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | =head2 host | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | my $host = $headers->host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | $headers = $headers->host('127.0.0.1'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | Get or replace current header value, shortcut for the C<Host> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | =head2 if_modified_since | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | my $date = $headers->if_modified_since; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | $headers = $headers->if_modified_since('Sun, 17 Aug 2008 16:27:35 GMT'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | Get or replace current header value, shortcut for the C<If-Modified-Since> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | =head2 if_none_match | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | my $etag = $headers->if_none_match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | $headers = $headers->if_none_match('"abc321"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | Get or replace current header value, shortcut for the C<If-None-Match> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | =head2 last_modified | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | my $date = $headers->last_modified; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | $headers = $headers->last_modified('Sun, 17 Aug 2008 16:27:35 GMT'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | Get or replace current header value, shortcut for the C<Last-Modified> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | =head2 link | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | my $link = $headers->link; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | $headers = $headers->link('<http://127.0.0.1/foo/3>; rel="next"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | Get or replace current header value, shortcut for the C<Link> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 5988|https://tools.ietf.org/html/rfc5988>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | =head2 links | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | my $links = $headers->links; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | $headers = $headers->links({next => 'http://example.com/foo', prev => 'http://example.com/bar'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | Get or set web links from or to C<Link> header according to L<RFC 5988|http://tools.ietf.org/html/rfc5988>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # Extract information about next page | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | say $headers->links->{next}{link}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | say $headers->links->{next}{title}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | =head2 location | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | my $location = $headers->location; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | $headers = $headers->location('http://127.0.0.1/foo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | Get or replace current header value, shortcut for the C<Location> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | =head2 origin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | my $origin = $headers->origin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | $headers = $headers->origin('http://example.com'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | Get or replace current header value, shortcut for the C<Origin> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 6454|https://tools.ietf.org/html/rfc6454>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | =head2 proxy_authenticate | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | my $authenticate = $headers->proxy_authenticate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | $headers = $headers->proxy_authenticate('Basic "realm"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | Get or replace current header value, shortcut for the C<Proxy-Authenticate> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | =head2 proxy_authorization | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | my $authorization = $headers->proxy_authorization; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | $headers = $headers->proxy_authorization('Basic Zm9vOmJhcg=='); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | Get or replace current header value, shortcut for the C<Proxy-Authorization> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | =head2 range | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | my $range = $headers->range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | $headers = $headers->range('bytes=2-8'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | Get or replace current header value, shortcut for the C<Range> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | =head2 referer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | my $referrer = $headers->referer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | $headers = $headers->referer('http://example.com'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | Alias for L</"referrer">. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | =head2 referrer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | my $referrer = $headers->referrer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | $headers = $headers->referrer('http://example.com'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | Get or replace current header value, shortcut for the C<Referer> header, there was a typo in L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 2068|https://tools.ietf.org/html/rfc2068> which resulted in C<Referer> becoming an official header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | =head2 sec_websocket_accept | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | my $accept = $headers->sec_websocket_accept; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | $headers = $headers->sec_websocket_accept('s3pPLMBiTxaQ9kYGzzhZRbK+xOo='); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | Get or replace current header value, shortcut for the C<Sec-WebSocket-Accept> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 6455|https://tools.ietf.org/html/rfc6455>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | =head2 sec_websocket_extensions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | my $extensions = $headers->sec_websocket_extensions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | $headers = $headers->sec_websocket_extensions('foo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | Get or replace current header value, shortcut for the C<Sec-WebSocket-Extensions> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 6455|https://tools.ietf.org/html/rfc6455>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | =head2 sec_websocket_key | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | my $key = $headers->sec_websocket_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | $headers = $headers->sec_websocket_key('dGhlIHNhbXBsZSBub25jZQ=='); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | Get or replace current header value, shortcut for the C<Sec-WebSocket-Key> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 6455|https://tools.ietf.org/html/rfc6455>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | =head2 sec_websocket_protocol | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | my $proto = $headers->sec_websocket_protocol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | $headers = $headers->sec_websocket_protocol('sample'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | Get or replace current header value, shortcut for the C<Sec-WebSocket-Protocol> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 6455|https://tools.ietf.org/html/rfc6455>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | =head2 sec_websocket_version | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | my $version = $headers->sec_websocket_version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | $headers = $headers->sec_websocket_version(13); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | Get or replace current header value, shortcut for the C<Sec-WebSocket-Version> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 6455|https://tools.ietf.org/html/rfc6455>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | =head2 server | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | my $server = $headers->server; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | $headers = $headers->server('Mojo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | Get or replace current header value, shortcut for the C<Server> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | =head2 server_timing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | my $timing = $headers->server_timing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | $headers = $headers->server_timing('app;desc=Mojolicious;dur=0.0001'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | Get or replace current header value, shortcut for the C<Server-Timing> header from L<Server | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | Timing|https://www.w3.org/TR/server-timing/>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | =head2 set_cookie | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | my $cookie = $headers->set_cookie; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | $headers = $headers->set_cookie('f=b; path=/'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | Get or replace current header value, shortcut for the C<Set-Cookie> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 6265|https://tools.ietf.org/html/rfc6265>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | =head2 status | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | my $status = $headers->status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | $headers = $headers->status('200 OK'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | Get or replace current header value, shortcut for the C<Status> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 3875|https://tools.ietf.org/html/rfc3875>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | =head2 strict_transport_security | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | my $policy = $headers->strict_transport_security; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | $headers = $headers->strict_transport_security('max-age=31536000'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | Get or replace current header value, shortcut for the C<Strict-Transport-Security> header from L<RFC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 6797|https://tools.ietf.org/html/rfc6797>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | =head2 te | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | my $te = $headers->te; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | $headers = $headers->te('chunked'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | Get or replace current header value, shortcut for the C<TE> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | =head2 trailer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | my $trailer = $headers->trailer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | $headers = $headers->trailer('X-Foo'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | Get or replace current header value, shortcut for the C<Trailer> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | =head2 transfer_encoding | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | my $encoding = $headers->transfer_encoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | $headers = $headers->transfer_encoding('chunked'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | Get or replace current header value, shortcut for the C<Transfer-Encoding> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | =head2 upgrade | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | my $upgrade = $headers->upgrade; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | $headers = $headers->upgrade('websocket'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | Get or replace current header value, shortcut for the C<Upgrade> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | =head2 user_agent | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | my $agent = $headers->user_agent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | $headers = $headers->user_agent('Mojo/1.0'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | Get or replace current header value, shortcut for the C<User-Agent> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | =head2 vary | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | my $vary = $headers->vary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | $headers = $headers->vary('*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | Get or replace current header value, shortcut for the C<Vary> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | =head2 www_authenticate | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | my $authenticate = $headers->www_authenticate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | $headers = $headers->www_authenticate('Basic realm="realm"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | Get or replace current header value, shortcut for the C<WWW-Authenticate> header. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | =head1 SEE ALSO | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||