Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / HTTP::Message.3pm
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sh \" Subsection heading
6 .br
7 .if t .Sp
8 .ne 5
9 .PP
10 \fB\\$1\fR
11 .PP
12 ..
13 .de Sp \" Vertical space (when we can't use .PP)
14 .if t .sp .5v
15 .if n .sp
16 ..
17 .de Vb \" Begin verbatim text
18 .ft CW
19 .nf
20 .ne \\$1
21 ..
22 .de Ve \" End verbatim text
23 .ft R
24 .fi
25 ..
26 .\" Set up some character translations and predefined strings.  \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote.  | will give a
29 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
32 .tr \(*W-|\(bv\*(Tr
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34 .ie n \{\
35 .    ds -- \(*W-
36 .    ds PI pi
37 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
39 .    ds L" ""
40 .    ds R" ""
41 .    ds C` ""
42 .    ds C' ""
43 'br\}
44 .el\{\
45 .    ds -- \|\(em\|
46 .    ds PI \(*p
47 .    ds L" ``
48 .    ds R" ''
49 'br\}
50 .\"
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD.  Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
55 .if \nF \{\
56 .    de IX
57 .    tm Index:\\$1\t\\n%\t"\\$2"
58 ..
59 .    nr % 0
60 .    rr F
61 .\}
62 .\"
63 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
65 .hy 0
66 .if n .na
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "HTTP::Message 3"
132 .TH HTTP::Message 3 "2009-11-21" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 HTTP::Message \- HTTP style message (base class)
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 1
138 \& use base 'HTTP::Message';
139 .Ve
140 .SH "DESCRIPTION"
141 .IX Header "DESCRIPTION"
142 An \f(CW\*(C`HTTP::Message\*(C'\fR object contains some headers and a content body.
143 The following methods are available:
144 .IP "$mess = HTTP::Message\->new" 4
145 .IX Item "$mess = HTTP::Message->new"
146 .PD 0
147 .ie n .IP "$mess = HTTP::Message\->new( $headers )" 4
148 .el .IP "$mess = HTTP::Message\->new( \f(CW$headers\fR )" 4
149 .IX Item "$mess = HTTP::Message->new( $headers )"
150 .ie n .IP "$mess = HTTP::Message\->new( $headers\fR, \f(CW$content )" 4
151 .el .IP "$mess = HTTP::Message\->new( \f(CW$headers\fR, \f(CW$content\fR )" 4
152 .IX Item "$mess = HTTP::Message->new( $headers, $content )"
153 .PD
154 This constructs a new message object.  Normally you would want
155 construct \f(CW\*(C`HTTP::Request\*(C'\fR or \f(CW\*(C`HTTP::Response\*(C'\fR objects instead.
156 .Sp
157 The optional \f(CW$header\fR argument should be a reference to an
158 \&\f(CW\*(C`HTTP::Headers\*(C'\fR object or a plain array reference of key/value pairs.
159 If an \f(CW\*(C`HTTP::Headers\*(C'\fR object is provided then a copy of it will be
160 embedded into the constructed message, i.e. it will not be owned and
161 can be modified afterwards without affecting the message.
162 .Sp
163 The optional \f(CW$content\fR argument should be a string of bytes.
164 .ie n .IP "$mess = HTTP::Message\->parse( $str )" 4
165 .el .IP "$mess = HTTP::Message\->parse( \f(CW$str\fR )" 4
166 .IX Item "$mess = HTTP::Message->parse( $str )"
167 This constructs a new message object by parsing the given string.
168 .IP "$mess\->headers" 4
169 .IX Item "$mess->headers"
170 Returns the embedded \f(CW\*(C`HTTP::Headers\*(C'\fR object.
171 .IP "$mess\->headers_as_string" 4
172 .IX Item "$mess->headers_as_string"
173 .PD 0
174 .ie n .IP "$mess\->headers_as_string( $eol )" 4
175 .el .IP "$mess\->headers_as_string( \f(CW$eol\fR )" 4
176 .IX Item "$mess->headers_as_string( $eol )"
177 .PD
178 Call the \fIas_string()\fR method for the headers in the
179 message.  This will be the same as
180 .Sp
181 .Vb 1
182 \&    $mess\->headers\->as_string
183 .Ve
184 .Sp
185 but it will make your program a whole character shorter :\-)
186 .IP "$mess\->content" 4
187 .IX Item "$mess->content"
188 .PD 0
189 .ie n .IP "$mess\->content( $bytes )" 4
190 .el .IP "$mess\->content( \f(CW$bytes\fR )" 4
191 .IX Item "$mess->content( $bytes )"
192 .PD
193 The \fIcontent()\fR method sets the raw content if an argument is given.  If no
194 argument is given the content is not touched.  In either case the
195 original raw content is returned.
196 .Sp
197 Note that the content should be a string of bytes.  Strings in perl
198 can contain characters outside the range of a byte.  The \f(CW\*(C`Encode\*(C'\fR
199 module can be used to turn such strings into a string of bytes.
200 .ie n .IP "$mess\->add_content( $bytes )" 4
201 .el .IP "$mess\->add_content( \f(CW$bytes\fR )" 4
202 .IX Item "$mess->add_content( $bytes )"
203 The \fIadd_content()\fR methods appends more data bytes to the end of the
204 current content buffer.
205 .ie n .IP "$mess\->add_content_utf8( $string )" 4
206 .el .IP "$mess\->add_content_utf8( \f(CW$string\fR )" 4
207 .IX Item "$mess->add_content_utf8( $string )"
208 The \fIadd_content_utf8()\fR method appends the \s-1UTF\-8\s0 bytes representing the
209 string to the end of the current content buffer.
210 .IP "$mess\->content_ref" 4
211 .IX Item "$mess->content_ref"
212 .PD 0
213 .IP "$mess\->content_ref( \e$bytes )" 4
214 .IX Item "$mess->content_ref( $bytes )"
215 .PD
216 The \fIcontent_ref()\fR method will return a reference to content buffer string.
217 It can be more efficient to access the content this way if the content
218 is huge, and it can even be used for direct manipulation of the content,
219 for instance:
220 .Sp
221 .Vb 1
222 \&  ${$res\->content_ref} =~ s/\ebfoo\eb/bar/g;
223 .Ve
224 .Sp
225 This example would modify the content buffer in\-place.
226 .Sp
227 If an argument is passed it will setup the content to reference some
228 external source.  The \fIcontent()\fR and \fIadd_content()\fR methods
229 will automatically dereference scalar references passed this way.  For
230 other references \fIcontent()\fR will return the reference itself and
231 \&\fIadd_content()\fR will refuse to do anything.
232 .IP "$mess\->content_charset" 4
233 .IX Item "$mess->content_charset"
234 This returns the charset used by the content in the message.  The
235 charset is either found as the charset attribute of the
236 \&\f(CW\*(C`Content\-Type\*(C'\fR header or by guessing.
237 .Sp
238 See <http://www.w3.org/TR/REC\-html40/charset.html#spec\-char\-encoding>
239 for details about how charset is determined.
240 .ie n .IP "$mess\->decoded_content( %options )" 4
241 .el .IP "$mess\->decoded_content( \f(CW%options\fR )" 4
242 .IX Item "$mess->decoded_content( %options )"
243 Returns the content with any \f(CW\*(C`Content\-Encoding\*(C'\fR undone and the raw
244 content encoded to perl's Unicode strings.  If the \f(CW\*(C`Content\-Encoding\*(C'\fR
245 or \f(CW\*(C`charset\*(C'\fR of the message is unknown this method will fail by
246 returning \f(CW\*(C`undef\*(C'\fR.
247 .Sp
248 The following options can be specified.
249 .RS 4
250 .ie n .IP """charset""" 4
251 .el .IP "\f(CWcharset\fR" 4
252 .IX Item "charset"
253 This override the charset parameter for text content.  The value
254 \&\f(CW\*(C`none\*(C'\fR can used to suppress decoding of the charset.
255 .ie n .IP """default_charset""" 4
256 .el .IP "\f(CWdefault_charset\fR" 4
257 .IX Item "default_charset"
258 This override the default charset guessed by \fIcontent_charset()\fR or
259 if that fails \*(L"\s-1ISO\-8859\-1\s0\*(R".
260 .ie n .IP """charset_strict""" 4
261 .el .IP "\f(CWcharset_strict\fR" 4
262 .IX Item "charset_strict"
263 Abort decoding if malformed characters is found in the content.  By
264 default you get the substitution character (\*(L"\ex{\s-1FFFD\s0}\*(R") in place of
265 malformed characters.
266 .ie n .IP """raise_error""" 4
267 .el .IP "\f(CWraise_error\fR" 4
268 .IX Item "raise_error"
269 If \s-1TRUE\s0 then raise an exception if not able to decode content.  Reason
270 might be that the specified \f(CW\*(C`Content\-Encoding\*(C'\fR or \f(CW\*(C`charset\*(C'\fR is not
271 supported.  If this option is \s-1FALSE\s0, then \fIdecoded_content()\fR will return
272 \&\f(CW\*(C`undef\*(C'\fR on errors, but will still set $@.
273 .ie n .IP """ref""" 4
274 .el .IP "\f(CWref\fR" 4
275 .IX Item "ref"
276 If \s-1TRUE\s0 then a reference to decoded content is returned.  This might
277 be more efficient in cases where the decoded content is identical to
278 the raw content as no data copying is required in this case.
279 .RE
280 .RS 4
281 .RE
282 .IP "$mess\->decodable" 4
283 .IX Item "$mess->decodable"
284 .PD 0
285 .IP "\fIHTTP::Message::decodable()\fR" 4
286 .IX Item "HTTP::Message::decodable()"
287 .PD
288 This returns the encoding identifiers that \fIdecoded_content()\fR can
289 process.  In scalar context returns a comma separated string of
290 identifiers.
291 .Sp
292 This value is suitable for initializing the \f(CW\*(C`Accept\-Encoding\*(C'\fR request
293 header field.
294 .IP "$mess\->decode" 4
295 .IX Item "$mess->decode"
296 This method tries to replace the content of the message with the
297 decoded version and removes the \f(CW\*(C`Content\-Encoding\*(C'\fR header.  Returns
298 \&\s-1TRUE\s0 if successful and \s-1FALSE\s0 if not.
299 .Sp
300 If the message does not have a \f(CW\*(C`Content\-Encoding\*(C'\fR header this method
301 does nothing and returns \s-1TRUE\s0.
302 .Sp
303 Note that the content of the message is still bytes after this method
304 has been called and you still need to call \fIdecoded_content()\fR if you
305 want to process its content as a string.
306 .ie n .IP "$mess\->encode( $encoding, ... )" 4
307 .el .IP "$mess\->encode( \f(CW$encoding\fR, ... )" 4
308 .IX Item "$mess->encode( $encoding, ... )"
309 Apply the given encodings to the content of the message.  Returns \s-1TRUE\s0
310 if successful. The \*(L"identity\*(R" (non\-)encoding is always supported; other
311 currently supported encodings, subject to availability of required
312 additional modules, are \*(L"gzip\*(R", \*(L"deflate\*(R", \*(L"x\-bzip2\*(R" and \*(L"base64\*(R".
313 .Sp
314 A successful call to this function will set the \f(CW\*(C`Content\-Encoding\*(C'\fR
315 header.
316 .Sp
317 Note that \f(CW\*(C`multipart/*\*(C'\fR or \f(CW\*(C`message/*\*(C'\fR messages can't be encoded and
318 this method will croak if you try.
319 .IP "$mess\->parts" 4
320 .IX Item "$mess->parts"
321 .PD 0
322 .ie n .IP "$mess\->parts( @parts )" 4
323 .el .IP "$mess\->parts( \f(CW@parts\fR )" 4
324 .IX Item "$mess->parts( @parts )"
325 .IP "$mess\->parts( \e@parts )" 4
326 .IX Item "$mess->parts( @parts )"
327 .PD
328 Messages can be composite, i.e. contain other messages.  The composite
329 messages have a content type of \f(CW\*(C`multipart/*\*(C'\fR or \f(CW\*(C`message/*\*(C'\fR.  This
330 method give access to the contained messages.
331 .Sp
332 The argumentless form will return a list of \f(CW\*(C`HTTP::Message\*(C'\fR objects.
333 If the content type of \f(CW$msg\fR is not \f(CW\*(C`multipart/*\*(C'\fR or \f(CW\*(C`message/*\*(C'\fR then
334 this will return the empty list.  In scalar context only the first
335 object is returned.  The returned message parts should be regarded as
336 read-only (future versions of this library might make it possible
337 to modify the parent by modifying the parts).
338 .Sp
339 If the content type of \f(CW$msg\fR is \f(CW\*(C`message/*\*(C'\fR then there will only be
340 one part returned.
341 .Sp
342 If the content type is \f(CW\*(C`message/http\*(C'\fR, then the return value will be
343 either an \f(CW\*(C`HTTP::Request\*(C'\fR or an \f(CW\*(C`HTTP::Response\*(C'\fR object.
344 .Sp
345 If an \f(CW@parts\fR argument is given, then the content of the message will be
346 modified. The array reference form is provided so that an empty list
347 can be provided.  The \f(CW@parts\fR array should contain \f(CW\*(C`HTTP::Message\*(C'\fR
348 objects.  The \f(CW@parts\fR objects are owned by \f(CW$mess\fR after this call and
349 should not be modified or made part of other messages.
350 .Sp
351 When updating the message with this method and the old content type of
352 \&\f(CW$mess\fR is not \f(CW\*(C`multipart/*\*(C'\fR or \f(CW\*(C`message/*\*(C'\fR, then the content type is
353 set to \f(CW\*(C`multipart/mixed\*(C'\fR and all other content headers are cleared.
354 .Sp
355 This method will croak if the content type is \f(CW\*(C`message/*\*(C'\fR and more
356 than one part is provided.
357 .ie n .IP "$mess\->add_part( $part )" 4
358 .el .IP "$mess\->add_part( \f(CW$part\fR )" 4
359 .IX Item "$mess->add_part( $part )"
360 This will add a part to a message.  The \f(CW$part\fR argument should be
361 another \f(CW\*(C`HTTP::Message\*(C'\fR object.  If the previous content type of
362 \&\f(CW$mess\fR is not \f(CW\*(C`multipart/*\*(C'\fR then the old content (together with all
363 content headers) will be made part #1 and the content type made
364 \&\f(CW\*(C`multipart/mixed\*(C'\fR before the new part is added.  The \f(CW$part\fR object is
365 owned by \f(CW$mess\fR after this call and should not be modified or made part
366 of other messages.
367 .Sp
368 There is no return value.
369 .IP "$mess\->clear" 4
370 .IX Item "$mess->clear"
371 Will clear the headers and set the content to the empty string.  There
372 is no return value
373 .IP "$mess\->protocol" 4
374 .IX Item "$mess->protocol"
375 .PD 0
376 .ie n .IP "$mess\->protocol( $proto )" 4
377 .el .IP "$mess\->protocol( \f(CW$proto\fR )" 4
378 .IX Item "$mess->protocol( $proto )"
379 .PD
380 Sets the \s-1HTTP\s0 protocol used for the message.  The \fIprotocol()\fR is a string
381 like \f(CW\*(C`HTTP/1.0\*(C'\fR or \f(CW\*(C`HTTP/1.1\*(C'\fR.
382 .IP "$mess\->clone" 4
383 .IX Item "$mess->clone"
384 Returns a copy of the message object.
385 .IP "$mess\->as_string" 4
386 .IX Item "$mess->as_string"
387 .PD 0
388 .ie n .IP "$mess\->as_string( $eol )" 4
389 .el .IP "$mess\->as_string( \f(CW$eol\fR )" 4
390 .IX Item "$mess->as_string( $eol )"
391 .PD
392 Returns the message formatted as a single string.
393 .Sp
394 The optional \f(CW$eol\fR parameter specifies the line ending sequence to use.
395 The default is \*(L"\en\*(R".  If no \f(CW$eol\fR is given then as_string will ensure
396 that the returned string is newline terminated (even when the message
397 content is not).  No extra newline is appended if an explicit \f(CW$eol\fR is
398 passed.
399 .ie n .IP "$mess\->dump( %opt )" 4
400 .el .IP "$mess\->dump( \f(CW%opt\fR )" 4
401 .IX Item "$mess->dump( %opt )"
402 Returns the message formatted as a string.  In void context print the string.
403 .Sp
404 This differs from \f(CW\*(C`$mess\->as_string\*(C'\fR in that it escapes the bytes
405 of the content so that it's safe to print them and it limits how much
406 content to print.  The escapes syntax used is the same as for Perl's
407 double quoted strings.  If there is no content the string \*(L"(no
408 content)\*(R" is shown in its place.
409 .Sp
410 Options to influence the output can be passed as key/value pairs. The
411 following options are recognized:
412 .RS 4
413 .ie n .IP "maxlength => $num" 4
414 .el .IP "maxlength => \f(CW$num\fR" 4
415 .IX Item "maxlength => $num"
416 How much of the content to show.  The default is 512.  Set this to 0
417 for unlimited.
418 .Sp
419 If the content is longer then the string is chopped at the limit and
420 the string \*(L"...\en(### more bytes not shown)\*(R" appended.
421 .ie n .IP "prefix => $str" 4
422 .el .IP "prefix => \f(CW$str\fR" 4
423 .IX Item "prefix => $str"
424 A string that will be prefixed to each line of the dump.
425 .RE
426 .RS 4
427 .RE
428 .PP
429 All methods unknown to \f(CW\*(C`HTTP::Message\*(C'\fR itself are delegated to the
430 \&\f(CW\*(C`HTTP::Headers\*(C'\fR object that is part of every message.  This allows
431 convenient access to these methods.  Refer to HTTP::Headers for
432 details of these methods:
433 .PP
434 .Vb 7
435 \&    $mess\->header( $field => $val )
436 \&    $mess\->push_header( $field => $val )
437 \&    $mess\->init_header( $field => $val )
438 \&    $mess\->remove_header( $field )
439 \&    $mess\->remove_content_headers
440 \&    $mess\->header_field_names
441 \&    $mess\->scan( \e&doit )
442 .Ve
443 .PP
444 .Vb 19
445 \&    $mess\->date
446 \&    $mess\->expires
447 \&    $mess\->if_modified_since
448 \&    $mess\->if_unmodified_since
449 \&    $mess\->last_modified
450 \&    $mess\->content_type
451 \&    $mess\->content_encoding
452 \&    $mess\->content_length
453 \&    $mess\->content_language
454 \&    $mess\->title
455 \&    $mess\->user_agent
456 \&    $mess\->server
457 \&    $mess\->from
458 \&    $mess\->referer
459 \&    $mess\->www_authenticate
460 \&    $mess\->authorization
461 \&    $mess\->proxy_authorization
462 \&    $mess\->authorization_basic
463 \&    $mess\->proxy_authorization_basic
464 .Ve
465 .SH "COPYRIGHT"
466 .IX Header "COPYRIGHT"
467 Copyright 1995\-2004 Gisle Aas.
468 .PP
469 This library is free software; you can redistribute it and/or
470 modify it under the same terms as Perl itself.