Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Net::HTTP.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 "Net::HTTP 3"
132 .TH Net::HTTP 3 "2009-11-21" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 Net::HTTP \- Low\-level HTTP connection (client)
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 4
138 \& use Net::HTTP;
139 \& my $s = Net::HTTP\->new(Host => "www.perl.com") || die $@;
140 \& $s\->write_request(GET => "/", 'User\-Agent' => "Mozilla/5.0");
141 \& my($code, $mess, %h) = $s\->read_response_headers;
142 .Ve
143 .PP
144 .Vb 7
145 \& while (1) {
146 \&    my $buf;
147 \&    my $n = $s\->read_entity_body($buf, 1024);
148 \&    die "read failed: $!" unless defined $n;
149 \&    last unless $n;
150 \&    print $buf;
151 \& }
152 .Ve
153 .SH "DESCRIPTION"
154 .IX Header "DESCRIPTION"
155 The \f(CW\*(C`Net::HTTP\*(C'\fR class is a low-level \s-1HTTP\s0 client.  An instance of the
156 \&\f(CW\*(C`Net::HTTP\*(C'\fR class represents a connection to an \s-1HTTP\s0 server.  The
157 \&\s-1HTTP\s0 protocol is described in \s-1RFC\s0 2616.  The \f(CW\*(C`Net::HTTP\*(C'\fR class
158 supports \f(CW\*(C`HTTP/1.0\*(C'\fR and \f(CW\*(C`HTTP/1.1\*(C'\fR.
159 .PP
160 \&\f(CW\*(C`Net::HTTP\*(C'\fR is a sub-class of \f(CW\*(C`IO::Socket::INET\*(C'\fR.  You can mix the
161 methods described below with reading and writing from the socket
162 directly.  This is not necessary a good idea, unless you know what you
163 are doing.
164 .PP
165 The following methods are provided (in addition to those of
166 \&\f(CW\*(C`IO::Socket::INET\*(C'\fR):
167 .ie n .IP "$s = Net::HTTP\->new( %options )" 4
168 .el .IP "$s = Net::HTTP\->new( \f(CW%options\fR )" 4
169 .IX Item "$s = Net::HTTP->new( %options )"
170 The \f(CW\*(C`Net::HTTP\*(C'\fR constructor method takes the same options as
171 \&\f(CW\*(C`IO::Socket::INET\*(C'\fR's as well as these:
172 .Sp
173 .Vb 7
174 \&  Host:            Initial host attribute value
175 \&  KeepAlive:       Initial keep_alive attribute value
176 \&  SendTE:          Initial send_te attribute_value
177 \&  HTTPVersion:     Initial http_version attribute value
178 \&  PeerHTTPVersion: Initial peer_http_version attribute value
179 \&  MaxLineLength:   Initial max_line_length attribute value
180 \&  MaxHeaderLines:  Initial max_header_lines attribute value
181 .Ve
182 .Sp
183 The \f(CW\*(C`Host\*(C'\fR option is also the default for \f(CW\*(C`IO::Socket::INET\*(C'\fR's
184 \&\f(CW\*(C`PeerAddr\*(C'\fR.  The \f(CW\*(C`PeerPort\*(C'\fR defaults to 80 if not provided.
185 .Sp
186 The \f(CW\*(C`Listen\*(C'\fR option provided by \f(CW\*(C`IO::Socket::INET\*(C'\fR's constructor
187 method is not allowed.
188 .Sp
189 If unable to connect to the given \s-1HTTP\s0 server then the constructor
190 returns \f(CW\*(C`undef\*(C'\fR and $@ contains the reason.  After a successful
191 connect, a \f(CW\*(C`Net:HTTP\*(C'\fR object is returned.
192 .IP "$s\->host" 4
193 .IX Item "$s->host"
194 Get/set the default value of the \f(CW\*(C`Host\*(C'\fR header to send.  The \f(CW$host\fR
195 must not be set to an empty string (or \f(CW\*(C`undef\*(C'\fR) for \s-1HTTP/1\s0.1.
196 .IP "$s\->keep_alive" 4
197 .IX Item "$s->keep_alive"
198 Get/set the \fIkeep-alive\fR value.  If this value is \s-1TRUE\s0 then the
199 request will be sent with headers indicating that the server should try
200 to keep the connection open so that multiple requests can be sent.
201 .Sp
202 The actual headers set will depend on the value of the \f(CW\*(C`http_version\*(C'\fR
203 and \f(CW\*(C`peer_http_version\*(C'\fR attributes.
204 .IP "$s\->send_te" 4
205 .IX Item "$s->send_te"
206 Get/set the a value indicating if the request will be sent with a \*(L"\s-1TE\s0\*(R"
207 header to indicate the transfer encodings that the server can choose to
208 use.  The list of encodings announced as accepted by this client depends
209 on availability of the following modules: \f(CW\*(C`Compress::Raw::Zlib\*(C'\fR for
210 \&\fIdeflate\fR, and \f(CW\*(C`IO::Compress::Gunzip\*(C'\fR for \fIgzip\fR.
211 .IP "$s\->http_version" 4
212 .IX Item "$s->http_version"
213 Get/set the \s-1HTTP\s0 version number that this client should announce.
214 This value can only be set to \*(L"1.0\*(R" or \*(L"1.1\*(R".  The default is \*(L"1.1\*(R".
215 .IP "$s\->peer_http_version" 4
216 .IX Item "$s->peer_http_version"
217 Get/set the protocol version number of our peer.  This value will
218 initially be \*(L"1.0\*(R", but will be updated by a successful
219 \&\fIread_response_headers()\fR method call.
220 .IP "$s\->max_line_length" 4
221 .IX Item "$s->max_line_length"
222 Get/set a limit on the length of response line and response header
223 lines.  The default is 8192.  A value of 0 means no limit.
224 .IP "$s\->max_header_length" 4
225 .IX Item "$s->max_header_length"
226 Get/set a limit on the number of header lines that a response can
227 have.  The default is 128.  A value of 0 means no limit.
228 .ie n .IP "$s\->format_request($method, $uri\fR, \f(CW%headers, [$content])" 4
229 .el .IP "$s\->format_request($method, \f(CW$uri\fR, \f(CW%headers\fR, [$content])" 4
230 .IX Item "$s->format_request($method, $uri, %headers, [$content])"
231 Format a request message and return it as a string.  If the headers do
232 not include a \f(CW\*(C`Host\*(C'\fR header, then a header is inserted with the value
233 of the \f(CW\*(C`host\*(C'\fR attribute.  Headers like \f(CW\*(C`Connection\*(C'\fR and
234 \&\f(CW\*(C`Keep\-Alive\*(C'\fR might also be added depending on the status of the
235 \&\f(CW\*(C`keep_alive\*(C'\fR attribute.
236 .Sp
237 If \f(CW$content\fR is given (and it is non\-empty), then a \f(CW\*(C`Content\-Length\*(C'\fR
238 header is automatically added unless it was already present.
239 .ie n .IP "$s\->write_request($method, $uri\fR, \f(CW%headers, [$content])" 4
240 .el .IP "$s\->write_request($method, \f(CW$uri\fR, \f(CW%headers\fR, [$content])" 4
241 .IX Item "$s->write_request($method, $uri, %headers, [$content])"
242 Format and send a request message.  Arguments are the same as for
243 \&\fIformat_request()\fR.  Returns true if successful.
244 .ie n .IP "$s\->format_chunk( $data )" 4
245 .el .IP "$s\->format_chunk( \f(CW$data\fR )" 4
246 .IX Item "$s->format_chunk( $data )"
247 Returns the string to be written for the given chunk of data.  
248 .IP "$s\->write_chunk($data)" 4
249 .IX Item "$s->write_chunk($data)"
250 Will write a new chunk of request entity body data.  This method
251 should only be used if the \f(CW\*(C`Transfer\-Encoding\*(C'\fR header with a value of
252 \&\f(CW\*(C`chunked\*(C'\fR was sent in the request.  Note, writing zero-length data is
253 a no\-op.  Use the \fIwrite_chunk_eof()\fR method to signal end of entity
254 body data.
255 .Sp
256 Returns true if successful.
257 .ie n .IP "$s\->format_chunk_eof( %trailers )" 4
258 .el .IP "$s\->format_chunk_eof( \f(CW%trailers\fR )" 4
259 .IX Item "$s->format_chunk_eof( %trailers )"
260 Returns the string to be written for signaling \s-1EOF\s0 when a
261 \&\f(CW\*(C`Transfer\-Encoding\*(C'\fR of \f(CW\*(C`chunked\*(C'\fR is used.
262 .ie n .IP "$s\->write_chunk_eof( %trailers )" 4
263 .el .IP "$s\->write_chunk_eof( \f(CW%trailers\fR )" 4
264 .IX Item "$s->write_chunk_eof( %trailers )"
265 Will write eof marker for chunked data and optional trailers.  Note
266 that trailers should not really be used unless is was signaled
267 with a \f(CW\*(C`Trailer\*(C'\fR header.
268 .Sp
269 Returns true if successful.
270 .ie n .IP "($code, $mess\fR, \f(CW%headers\fR) = \f(CW$s\fR\->read_response_headers( \f(CW%opts )" 4
271 .el .IP "($code, \f(CW$mess\fR, \f(CW%headers\fR) = \f(CW$s\fR\->read_response_headers( \f(CW%opts\fR )" 4
272 .IX Item "($code, $mess, %headers) = $s->read_response_headers( %opts )"
273 Read response headers from server and return it.  The \f(CW$code\fR is the 3
274 digit \s-1HTTP\s0 status code (see HTTP::Status) and \f(CW$mess\fR is the textual
275 message that came with it.  Headers are then returned as key/value
276 pairs.  Since key letter casing is not normalized and the same key can
277 even occur multiple times, assigning these values directly to a hash
278 is not wise.  Only the \f(CW$code\fR is returned if this method is called in
279 scalar context.
280 .Sp
281 As a side effect this method updates the 'peer_http_version'
282 attribute.
283 .Sp
284 Options might be passed in as key/value pairs.  There are currently
285 only two options supported; \f(CW\*(C`laxed\*(C'\fR and \f(CW\*(C`junk_out\*(C'\fR.
286 .Sp
287 The \f(CW\*(C`laxed\*(C'\fR option will make \fIread_response_headers()\fR more forgiving
288 towards servers that have not learned how to speak \s-1HTTP\s0 properly.  The
289 \&\f(CW\*(C`laxed\*(C'\fR option is a boolean flag, and is enabled by passing in a \s-1TRUE\s0
290 value.  The \f(CW\*(C`junk_out\*(C'\fR option can be used to capture bad header lines
291 when \f(CW\*(C`laxed\*(C'\fR is enabled.  The value should be an array reference.
292 Bad header lines will be pushed onto the array.
293 .Sp
294 The \f(CW\*(C`laxed\*(C'\fR option must be specified in order to communicate with
295 pre\-HTTP/1.0 servers that don't describe the response outcome or the
296 data they send back with a header block.  For these servers
297 peer_http_version is set to \*(L"0.9\*(R" and this method returns (200,
298 \&\*(L"Assumed \s-1OK\s0\*(R").
299 .Sp
300 The method will raise an exception (die) if the server does not speak
301 proper \s-1HTTP\s0 or if the \f(CW\*(C`max_line_length\*(C'\fR or \f(CW\*(C`max_header_length\*(C'\fR
302 limits are reached.  If the \f(CW\*(C`laxed\*(C'\fR option is turned on and
303 \&\f(CW\*(C`max_line_length\*(C'\fR and \f(CW\*(C`max_header_length\*(C'\fR checks are turned off,
304 then no exception will be raised and this method will always
305 return a response code.
306 .ie n .IP "$n = $s\fR\->read_entity_body($buf, \f(CW$size);" 4
307 .el .IP "$n = \f(CW$s\fR\->read_entity_body($buf, \f(CW$size\fR);" 4
308 .IX Item "$n = $s->read_entity_body($buf, $size);"
309 Reads chunks of the entity body content.  Basically the same interface
310 as for \fIread()\fR and \fIsysread()\fR, but the buffer offset argument is not
311 supported yet.  This method should only be called after a successful
312 \&\fIread_response_headers()\fR call.
313 .Sp
314 The return value will be \f(CW\*(C`undef\*(C'\fR on read errors, 0 on \s-1EOF\s0, \-1 if no data
315 could be returned this time, otherwise the number of bytes assigned
316 to \f(CW$buf\fR.  The \f(CW$buf\fR is set to "" when the return value is \-1.
317 .Sp
318 You normally want to retry this call if this function returns either
319 \&\-1 or \f(CW\*(C`undef\*(C'\fR with \f(CW$!\fR as \s-1EINTR\s0 or \s-1EAGAIN\s0 (see Errno).  \s-1EINTR\s0
320 can happen if the application catches signals and \s-1EAGAIN\s0 can happen if
321 you made the socket non\-blocking.
322 .Sp
323 This method will raise exceptions (die) if the server does not speak
324 proper \s-1HTTP\s0.  This can only happen when reading chunked data.
325 .ie n .IP "%headers = $s\->get_trailers" 4
326 .el .IP "%headers = \f(CW$s\fR\->get_trailers" 4
327 .IX Item "%headers = $s->get_trailers"
328 After \fIread_entity_body()\fR has returned 0 to indicate end of the entity
329 body, you might call this method to pick up any trailers.
330 .IP "$s\->_rbuf" 4
331 .IX Item "$s->_rbuf"
332 Get/set the read buffer content.  The \fIread_response_headers()\fR and
333 \&\fIread_entity_body()\fR methods use an internal buffer which they will look
334 for data before they actually sysread more from the socket itself.  If
335 they read too much, the remaining data will be left in this buffer.
336 .IP "$s\->_rbuf_length" 4
337 .IX Item "$s->_rbuf_length"
338 Returns the number of bytes in the read buffer.  This should always be
339 the same as:
340 .Sp
341 .Vb 1
342 \&    length($s\->_rbuf)
343 .Ve
344 .Sp
345 but might be more efficient.
346 .SH "SUBCLASSING"
347 .IX Header "SUBCLASSING"
348 The \fIread_response_headers()\fR and \fIread_entity_body()\fR will invoke the
349 \&\fIsysread()\fR method when they need more data.  Subclasses might want to
350 override this method to control how reading takes place.
351 .PP
352 The object itself is a glob.  Subclasses should avoid using hash key
353 names prefixed with \f(CW\*(C`http_\*(C'\fR and \f(CW\*(C`io_\*(C'\fR.
354 .SH "SEE ALSO"
355 .IX Header "SEE ALSO"
356 \&\s-1LWP\s0, IO::Socket::INET, Net::HTTP::NB
357 .SH "COPYRIGHT"
358 .IX Header "COPYRIGHT"
359 Copyright 2001\-2003 Gisle Aas.
360 .PP
361 This library is free software; you can redistribute it and/or
362 modify it under the same terms as Perl itself.