1Mojo::Headers(3)      User Contributed Perl Documentation     Mojo::Headers(3)
2
3
4

NAME

6       Mojo::Headers - Headers
7

SYNOPSIS

9           use Mojo::Headers;
10
11           my $headers = Mojo::Headers->new;
12           $headers->content_type('text/plain');
13           $headers->parse("Content-Type: text/html\n\n");
14           print "$headers";
15

DESCRIPTION

17       Mojo::Headers is a container and parser for HTTP headers.
18

ATTRIBUTES

20       Mojo::Headers implements the following attributes.
21
22   "buffer"
23           my $buffer = $headers->buffer;
24           $headers   = $headers->buffer(Mojo::ByteStream->new);
25
26       The Buffer to use for header parsing, by default a Mojo::ByteStream
27       object.
28

METHODS

30       Mojo::Headers inherits all methods from Mojo::Base and implements the
31       following new ones.
32
33   "accept_language"
34           my $accept_language = $headers->accept_language;
35           $headers            = $headers->accept_language('de, en');
36
37       Shortcut for the "Accept-Language" header.
38
39   "accept_ranges"
40           my $ranges = $headers->accept_ranges;
41           $headers   = $headers->accept_ranges('bytes');
42
43       Shortcut for the "Accept-Ranges" header.
44
45   "add"
46           $headers = $headers->add('Content-Type', 'text/plain');
47
48       Add one or more header lines.
49
50   "authorization"
51           my $authorization = $headers->authorization;
52           $headers          = $headers->authorization('Basic Zm9vOmJhcg==');
53
54       Shortcut for the "Authorization" header.
55
56   "to_string"
57   "build"
58           my $string = $headers->build;
59           my $string = $headers->to_string;
60           my $string = "$headers";
61
62       Format headers suitable for HTTP 1.1 messages.
63
64   "connection"
65           my $connection = $headers->connection;
66           $headers       = $headers->connection('close');
67
68       Shortcut for the "Connection" header.
69
70   "content_disposition"
71           my $content_disposition = $headers->content_disposition;
72           $headers                = $headers->content_disposition('foo');
73
74       Shortcut for the "Content-Disposition" header.
75
76   "content_length"
77           my $content_length = $headers->content_length;
78           $headers           = $headers->content_length(4000);
79
80       Shortcut for the "Content-Length" header.
81
82   "content_range"
83           my $range = $headers->content_range;
84           $headers  = $headers->content_range('bytes 2-8/100');
85
86       Shortcut for the "Content-Range" header.
87
88   "content_transfer_encoding"
89           my $encoding = $headers->content_transfer_encoding;
90           $headers     = $headers->content_transfer_encoding('foo');
91
92       Shortcut for the "Content-Transfer-Encoding" header.
93
94   "content_type"
95           my $content_type = $headers->content_type;
96           $headers         = $headers->content_type('text/plain');
97
98       Shortcut for the "Content-Type" header.
99
100   "cookie"
101           my $cookie = $headers->cookie;
102           $headers   = $headers->cookie('$Version=1; f=b; $Path=/');
103
104       Shortcut for the "Cookie" header.
105
106   "date"
107           my $date = $headers->date;
108           $headers = $headers->date('Sun, 17 Aug 2008 16:27:35 GMT');
109
110       Shortcut for the "Date" header.
111
112   "expect"
113           my $expect = $headers->expect;
114           $headers   = $headers->expect('100-continue');
115
116       Shortcut for the "Expect" header.
117
118   "from_hash"
119           $headers = $headers->from_hash({'Content-Type' => 'text/html'});
120
121       Parse headers from a hash.
122
123   "header"
124           my $string = $headers->header('Content-Type');
125           my @lines  = $headers->header('Content-Type');
126           $headers   = $headers->header('Content-Type' => 'text/plain');
127
128       Get or replace the current header values.  Note that this method is
129       context sensitive and will turn all header lines into a single one in
130       scalar context.
131
132   "host"
133           my $host = $headers->host;
134           $headers = $headers->host('127.0.0.1');
135
136       Shortcut for the "Host" header.
137
138   "if_modified_since"
139           my $m    = $headers->if_modified_since;
140           $headers = $headers->if_modified_since('Sun, 17 Aug 2008 16:27:35 GMT');
141
142       Shortcut for the "If-Modified-Since" header.
143
144   "is_done"
145           my $done = $headers->is_done;
146
147       Check if header parser is done.
148
149   "last_modified"
150           my $m    = $headers->last_modified;
151           $headers = $headers->last_modified('Sun, 17 Aug 2008 16:27:35 GMT');
152
153       Shortcut for the "Last-Modified" header.
154
155   "location"
156           my $location = $headers->location;
157           $headers     = $headers->location('http://127.0.0.1/foo');
158
159       Shortcut for the "Location" header.
160
161   "names"
162           my $names = $headers->names;
163
164       Generate a list of all currently defined headers.
165
166   "origin"
167           my $origin = $headers->origin;
168           $headers   = $headers->origin('http://example.com');
169
170       Shortcut for the "Origin" header.
171
172   "parse"
173           my $success = $headers->parse("Content-Type: text/foo\n\n");
174
175       Parse formatted headers.
176
177   "proxy_authenticate"
178           my $authenticate = $headers->proxy_authenticate;
179           $headers         = $headers->proxy_authenticate('Basic "realm"');
180
181       Shortcut for the "Proxy-Authenticate" header.
182
183   "proxy_authorization"
184           my $proxy_authorization = $headers->proxy_authorization;
185           $headers = $headers->proxy_authorization('Basic Zm9vOmJhcg==');
186
187       Shortcut for the "Proxy-Authorization" header.
188
189   "range"
190           my $range = $headers->range;
191           $headers  = $headers->range('bytes=2-8');
192
193       Shortcut for the "Range" header.
194
195   "referrer"
196           my $referrer = $headers->referrer;
197           $headers     = $headers->referrer('http://mojolicious.org');
198
199       Shortcut for the "Referer" header, there was a typo in RFC 2068 which
200       resulted in "Referer" becoming an official header.
201
202   "remove"
203           $headers = $headers->remove('Content-Type');
204
205       Remove a header.
206
207   "sec_websocket_key1"
208           my $key1 = $headers->sec_websocket_key1;
209           $headers = $headers->sec_websocket_key1('4 @1  46546xW%0l 1 5');
210
211       Shortcut for the "Sec-WebSocket-Key1" header.
212
213   "sec_websocket_key2"
214           my $key2 = $headers->sec_websocket_key2;
215           $headers = $headers->sec_websocket_key2('12998 5 Y3 1  .P00');
216
217       Shortcut for the "Sec-WebSocket-Key2" header.
218
219   "sec_websocket_location"
220           my $location = $headers->sec_websocket_location;
221           $headers     = $headers->sec_websocket_location('ws://example.com/demo');
222
223       Shortcut for the "Sec-WebSocket-Location" header.
224
225   "sec_websocket_origin"
226           my $origin = $headers->sec_websocket_origin;
227           $headers   = $headers->sec_websocket_origin('http://example.com');
228
229       Shortcut for the "Sec-WebSocket-Origin" header.
230
231   "sec_websocket_protocol"
232           my $protocol = $headers->sec_websocket_protocol;
233           $headers     = $headers->sec_websocket_protocol('sample');
234
235       Shortcut for the "Sec-WebSocket-Protocol" header.
236
237   "server"
238           my $server = $headers->server;
239           $headers   = $headers->server('Mojo');
240
241       Shortcut for the "Server" header.
242
243   "set_cookie"
244           my $set_cookie = $headers->set_cookie;
245           $headers       = $headers->set_cookie('f=b; Version=1; Path=/');
246
247       Shortcut for the "Set-Cookie" header.
248
249   "set_cookie2"
250           my $set_cookie2 = $headers->set_cookie2;
251           $headers        = $headers->set_cookie2('f=b; Version=1; Path=/');
252
253       Shortcut for the "Set-Cookie2" header.
254
255   "status"
256           my $status = $headers->status;
257           $headers   = $headers->status('200 OK');
258
259       Shortcut for the "Status" header.
260
261   "to_hash"
262           my $hash = $headers->to_hash;
263           my $hash = $headers->to_hash(arrayref => 1);
264
265       Format headers as a hash.  Nested arrayrefs to represent multi line
266       values are optional.
267
268   "trailer"
269           my $trailer = $headers->trailer;
270           $headers    = $headers->trailer('X-Foo');
271
272       Shortcut for the "Trailer" header.
273
274   "transfer_encoding"
275           my $transfer_encoding = $headers->transfer_encoding;
276           $headers              = $headers->transfer_encoding('chunked');
277
278       Shortcut for the "Transfer-Encoding" header.
279
280   "upgrade"
281           my $upgrade = $headers->upgrade;
282           $headers    = $headers->upgrade('WebSocket');
283
284       Shortcut for the "Upgrade" header.
285
286   "user_agent"
287           my $user_agent = $headers->user_agent;
288           $headers       = $headers->user_agent('Mojo/1.0');
289
290       Shortcut for the "User-Agent" header.
291
292   "www_authenticate"
293           my $authenticate = $headers->www_authenticate;
294           $headers         = $headers->www_authenticate('Basic "realm"');
295
296       Shortcut for the "WWW-Authenticate" header.
297

SEE ALSO

299       Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
300
301
302
303perl v5.12.3                      2010-08-12                  Mojo::Headers(3)
Impressum