File Coverage

blib/lib/Mojo/Headers.pm
Criterion Covered Total %
statement 104 104 100.0
branch 32 32 100.0
condition 21 26 80.7
subroutine 72 72 100.0
pod 18 18 100.0
total 247 252 98.0


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