Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / HTTP::Daemon.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::Daemon 3"
132 .TH HTTP::Daemon 3 "2009-06-15" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 HTTP::Daemon \- a simple http server class
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 2
138 \&  use HTTP::Daemon;
139 \&  use HTTP::Status;
140 .Ve
141 .PP
142 .Vb 15
143 \&  my $d = HTTP::Daemon\->new || die;
144 \&  print "Please contact me at: <URL:", $d\->url, ">\en";
145 \&  while (my $c = $d\->accept) {
146 \&      while (my $r = $c\->get_request) {
147 \&          if ($r\->method eq 'GET' and $r\->uri\->path eq "/xyzzy") {
148 \&              # remember, this is *not* recommended practice :\-)
149 \&              $c\->send_file_response("/etc/passwd");
150 \&          }
151 \&          else {
152 \&              $c\->send_error(RC_FORBIDDEN)
153 \&          }
154 \&      }
155 \&      $c\->close;
156 \&      undef($c);
157 \&  }
158 .Ve
159 .SH "DESCRIPTION"
160 .IX Header "DESCRIPTION"
161 Instances of the \f(CW\*(C`HTTP::Daemon\*(C'\fR class are \s-1HTTP/1\s0.1 servers that
162 listen on a socket for incoming requests. The \f(CW\*(C`HTTP::Daemon\*(C'\fR is a
163 subclass of \f(CW\*(C`IO::Socket::INET\*(C'\fR, so you can perform socket operations
164 directly on it too.
165 .PP
166 The \fIaccept()\fR method will return when a connection from a client is
167 available.  The returned value will be an \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fR
168 object which is another \f(CW\*(C`IO::Socket::INET\*(C'\fR subclass.  Calling the
169 \&\fIget_request()\fR method on this object will read data from the client and
170 return an \f(CW\*(C`HTTP::Request\*(C'\fR object.  The ClientConn object also provide
171 methods to send back various responses.
172 .PP
173 This \s-1HTTP\s0 daemon does not \fIfork\fR\|(2) for you.  Your application, i.e. the
174 user of the \f(CW\*(C`HTTP::Daemon\*(C'\fR is responsible for forking if that is
175 desirable.  Also note that the user is responsible for generating
176 responses that conform to the \s-1HTTP/1\s0.1 protocol.
177 .PP
178 The following methods of \f(CW\*(C`HTTP::Daemon\*(C'\fR are new (or enhanced) relative
179 to the \f(CW\*(C`IO::Socket::INET\*(C'\fR base class:
180 .IP "$d = HTTP::Daemon\->new" 4
181 .IX Item "$d = HTTP::Daemon->new"
182 .PD 0
183 .ie n .IP "$d = HTTP::Daemon\->new( %opts )" 4
184 .el .IP "$d = HTTP::Daemon\->new( \f(CW%opts\fR )" 4
185 .IX Item "$d = HTTP::Daemon->new( %opts )"
186 .PD
187 The constructor method takes the same arguments as the
188 \&\f(CW\*(C`IO::Socket::INET\*(C'\fR constructor, but unlike its base class it can also
189 be called without any arguments.  The daemon will then set up a listen
190 queue of 5 connections and allocate some random port number.
191 .Sp
192 A server that wants to bind to some specific address on the standard
193 \&\s-1HTTP\s0 port will be constructed like this:
194 .Sp
195 .Vb 4
196 \&  $d = HTTP::Daemon\->new(
197 \&           LocalAddr => 'www.thisplace.com',
198 \&           LocalPort => 80,
199 \&       );
200 .Ve
201 .Sp
202 See IO::Socket::INET for a description of other arguments that can
203 be used configure the daemon during construction.
204 .ie n .IP "$c = $d\->accept" 4
205 .el .IP "$c = \f(CW$d\fR\->accept" 4
206 .IX Item "$c = $d->accept"
207 .PD 0
208 .ie n .IP "$c = $d\fR\->accept( \f(CW$pkg )" 4
209 .el .IP "$c = \f(CW$d\fR\->accept( \f(CW$pkg\fR )" 4
210 .IX Item "$c = $d->accept( $pkg )"
211 .ie n .IP "($c, $peer_addr\fR) = \f(CW$d\->accept" 4
212 .el .IP "($c, \f(CW$peer_addr\fR) = \f(CW$d\fR\->accept" 4
213 .IX Item "($c, $peer_addr) = $d->accept"
214 .PD
215 This method works the same the one provided by the base class, but it
216 returns an \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fR reference by default.  If a
217 package name is provided as argument, then the returned object will be
218 blessed into the given class.  It is probably a good idea to make that
219 class a subclass of \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fR.
220 .Sp
221 The accept method will return \f(CW\*(C`undef\*(C'\fR if timeouts have been enabled
222 and no connection is made within the given time.  The \fItimeout()\fR method
223 is described in IO::Socket.
224 .Sp
225 In list context both the client object and the peer address will be
226 returned; see the description of the accept method IO::Socket for
227 details.
228 .IP "$d\->url" 4
229 .IX Item "$d->url"
230 Returns a \s-1URL\s0 string that can be used to access the server root.
231 .IP "$d\->product_tokens" 4
232 .IX Item "$d->product_tokens"
233 Returns the name that this server will use to identify itself.  This
234 is the string that is sent with the \f(CW\*(C`Server\*(C'\fR response header.  The
235 main reason to have this method is that subclasses can override it if
236 they want to use another product name.
237 .Sp
238 The default is the string \*(L"libwww\-perl\-daemon/#.##\*(R" where \*(L"#.##\*(R" is
239 replaced with the version number of this module.
240 .PP
241 The \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fR is a \f(CW\*(C`IO::Socket::INET\*(C'\fR
242 subclass. Instances of this class are returned by the \fIaccept()\fR method
243 of \f(CW\*(C`HTTP::Daemon\*(C'\fR.  The following methods are provided:
244 .IP "$c\->get_request" 4
245 .IX Item "$c->get_request"
246 .PD 0
247 .ie n .IP "$c\->get_request( $headers_only )" 4
248 .el .IP "$c\->get_request( \f(CW$headers_only\fR )" 4
249 .IX Item "$c->get_request( $headers_only )"
250 .PD
251 This method reads data from the client and turns it into an
252 \&\f(CW\*(C`HTTP::Request\*(C'\fR object which is returned.  It returns \f(CW\*(C`undef\*(C'\fR
253 if reading fails.  If it fails, then the \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fR
254 object ($c) should be discarded, and you should not try call this
255 method again on it.  The \f(CW$c\fR\->reason method might give you some
256 information about why \f(CW$c\fR\->get_request failed.
257 .Sp
258 The \fIget_request()\fR method will normally not return until the whole
259 request has been received from the client.  This might not be what you
260 want if the request is an upload of a large file (and with chunked
261 transfer encoding \s-1HTTP\s0 can even support infinite request messages \-
262 uploading live audio for instance).  If you pass a \s-1TRUE\s0 value as the
263 \&\f(CW$headers_only\fR argument, then \fIget_request()\fR will return immediately
264 after parsing the request headers and you are responsible for reading
265 the rest of the request content.  If you are going to call
266 \&\f(CW$c\fR\->get_request again on the same connection you better read the
267 correct number of bytes.
268 .IP "$c\->read_buffer" 4
269 .IX Item "$c->read_buffer"
270 .PD 0
271 .ie n .IP "$c\->read_buffer( $new_value )" 4
272 .el .IP "$c\->read_buffer( \f(CW$new_value\fR )" 4
273 .IX Item "$c->read_buffer( $new_value )"
274 .PD
275 Bytes read by \f(CW$c\fR\->get_request, but not used are placed in the \fIread
276 buffer\fR.  The next time \f(CW$c\fR\->get_request is called it will consume the
277 bytes in this buffer before reading more data from the network
278 connection itself.  The read buffer is invalid after \f(CW$c\fR\->get_request
279 has failed.
280 .Sp
281 If you handle the reading of the request content yourself you need to
282 empty this buffer before you read more and you need to place
283 unconsumed bytes here.  You also need this buffer if you implement
284 services like \fI101 Switching Protocols\fR.
285 .Sp
286 This method always returns the old buffer content and can optionally
287 replace the buffer content if you pass it an argument.
288 .IP "$c\->reason" 4
289 .IX Item "$c->reason"
290 When \f(CW$c\fR\->get_request returns \f(CW\*(C`undef\*(C'\fR you can obtain a short string
291 describing why it happened by calling \f(CW$c\fR\->reason.
292 .ie n .IP "$c\->proto_ge( $proto )" 4
293 .el .IP "$c\->proto_ge( \f(CW$proto\fR )" 4
294 .IX Item "$c->proto_ge( $proto )"
295 Return \s-1TRUE\s0 if the client announced a protocol with version number
296 greater or equal to the given argument.  The \f(CW$proto\fR argument can be a
297 string like \*(L"\s-1HTTP/1\s0.1\*(R" or just \*(L"1.1\*(R".
298 .IP "$c\->antique_client" 4
299 .IX Item "$c->antique_client"
300 Return \s-1TRUE\s0 if the client speaks the \s-1HTTP/0\s0.9 protocol.  No status
301 code and no headers should be returned to such a client.  This should
302 be the same as !$c\->proto_ge(\*(L"\s-1HTTP/1\s0.0\*(R").
303 .IP "$c\->head_request" 4
304 .IX Item "$c->head_request"
305 Return \s-1TRUE\s0 if the last request was a \f(CW\*(C`HEAD\*(C'\fR request.  No content
306 body must be generated for these requests.
307 .IP "$c\->force_last_request" 4
308 .IX Item "$c->force_last_request"
309 Make sure that \f(CW$c\fR\->get_request will not try to read more requests off
310 this connection.  If you generate a response that is not self
311 delimiting, then you should signal this fact by calling this method.
312 .Sp
313 This attribute is turned on automatically if the client announces
314 protocol \s-1HTTP/1\s0.0 or worse and does not include a \*(L"Connection:
315 Keep\-Alive\*(R" header.  It is also turned on automatically when \s-1HTTP/1\s0.1
316 or better clients send the \*(L"Connection: close\*(R" request header.
317 .IP "$c\->send_status_line" 4
318 .IX Item "$c->send_status_line"
319 .PD 0
320 .ie n .IP "$c\->send_status_line( $code )" 4
321 .el .IP "$c\->send_status_line( \f(CW$code\fR )" 4
322 .IX Item "$c->send_status_line( $code )"
323 .ie n .IP "$c\->send_status_line( $code\fR, \f(CW$mess )" 4
324 .el .IP "$c\->send_status_line( \f(CW$code\fR, \f(CW$mess\fR )" 4
325 .IX Item "$c->send_status_line( $code, $mess )"
326 .ie n .IP "$c\->send_status_line( $code\fR, \f(CW$mess\fR, \f(CW$proto )" 4
327 .el .IP "$c\->send_status_line( \f(CW$code\fR, \f(CW$mess\fR, \f(CW$proto\fR )" 4
328 .IX Item "$c->send_status_line( $code, $mess, $proto )"
329 .PD
330 Send the status line back to the client.  If \f(CW$code\fR is omitted 200 is
331 assumed.  If \f(CW$mess\fR is omitted, then a message corresponding to \f(CW$code\fR
332 is inserted.  If \f(CW$proto\fR is missing the content of the
333 \&\f(CW$HTTP::Daemon::PROTO\fR variable is used.
334 .IP "$c\->send_crlf" 4
335 .IX Item "$c->send_crlf"
336 Send the \s-1CRLF\s0 sequence to the client.
337 .IP "$c\->send_basic_header" 4
338 .IX Item "$c->send_basic_header"
339 .PD 0
340 .ie n .IP "$c\->send_basic_header( $code )" 4
341 .el .IP "$c\->send_basic_header( \f(CW$code\fR )" 4
342 .IX Item "$c->send_basic_header( $code )"
343 .ie n .IP "$c\->send_basic_header( $code\fR, \f(CW$mess )" 4
344 .el .IP "$c\->send_basic_header( \f(CW$code\fR, \f(CW$mess\fR )" 4
345 .IX Item "$c->send_basic_header( $code, $mess )"
346 .ie n .IP "$c\->send_basic_header( $code\fR, \f(CW$mess\fR, \f(CW$proto )" 4
347 .el .IP "$c\->send_basic_header( \f(CW$code\fR, \f(CW$mess\fR, \f(CW$proto\fR )" 4
348 .IX Item "$c->send_basic_header( $code, $mess, $proto )"
349 .PD
350 Send the status line and the \*(L"Date:\*(R" and \*(L"Server:\*(R" headers back to
351 the client.  This header is assumed to be continued and does not end
352 with an empty \s-1CRLF\s0 line.
353 .Sp
354 See the description of \fIsend_status_line()\fR for the description of the
355 accepted arguments.
356 .ie n .IP "$c\->send_header( $field\fR, \f(CW$value )" 4
357 .el .IP "$c\->send_header( \f(CW$field\fR, \f(CW$value\fR )" 4
358 .IX Item "$c->send_header( $field, $value )"
359 .PD 0
360 .ie n .IP "$c\->send_header( $field1\fR, \f(CW$value1\fR, \f(CW$field2\fR, \f(CW$value2, ... )" 4
361 .el .IP "$c\->send_header( \f(CW$field1\fR, \f(CW$value1\fR, \f(CW$field2\fR, \f(CW$value2\fR, ... )" 4
362 .IX Item "$c->send_header( $field1, $value1, $field2, $value2, ... )"
363 .PD
364 Send one or more header lines.
365 .ie n .IP "$c\->send_response( $res )" 4
366 .el .IP "$c\->send_response( \f(CW$res\fR )" 4
367 .IX Item "$c->send_response( $res )"
368 Write a \f(CW\*(C`HTTP::Response\*(C'\fR object to the
369 client as a response.  We try hard to make sure that the response is
370 self delimiting so that the connection can stay persistent for further
371 request/response exchanges.
372 .Sp
373 The content attribute of the \f(CW\*(C`HTTP::Response\*(C'\fR object can be a normal
374 string or a subroutine reference.  If it is a subroutine, then
375 whatever this callback routine returns is written back to the
376 client as the response content.  The routine will be called until it
377 return an undefined or empty value.  If the client is \s-1HTTP/1\s0.1 aware
378 then we will use chunked transfer encoding for the response.
379 .ie n .IP "$c\->send_redirect( $loc )" 4
380 .el .IP "$c\->send_redirect( \f(CW$loc\fR )" 4
381 .IX Item "$c->send_redirect( $loc )"
382 .PD 0
383 .ie n .IP "$c\->send_redirect( $loc\fR, \f(CW$code )" 4
384 .el .IP "$c\->send_redirect( \f(CW$loc\fR, \f(CW$code\fR )" 4
385 .IX Item "$c->send_redirect( $loc, $code )"
386 .ie n .IP "$c\->send_redirect( $loc\fR, \f(CW$code\fR, \f(CW$entity_body )" 4
387 .el .IP "$c\->send_redirect( \f(CW$loc\fR, \f(CW$code\fR, \f(CW$entity_body\fR )" 4
388 .IX Item "$c->send_redirect( $loc, $code, $entity_body )"
389 .PD
390 Send a redirect response back to the client.  The location ($loc) can
391 be an absolute or relative \s-1URL\s0. The \f(CW$code\fR must be one the redirect
392 status codes, and defaults to \*(L"301 Moved Permanently\*(R"
393 .IP "$c\->send_error" 4
394 .IX Item "$c->send_error"
395 .PD 0
396 .ie n .IP "$c\->send_error( $code )" 4
397 .el .IP "$c\->send_error( \f(CW$code\fR )" 4
398 .IX Item "$c->send_error( $code )"
399 .ie n .IP "$c\->send_error( $code\fR, \f(CW$error_message )" 4
400 .el .IP "$c\->send_error( \f(CW$code\fR, \f(CW$error_message\fR )" 4
401 .IX Item "$c->send_error( $code, $error_message )"
402 .PD
403 Send an error response back to the client.  If the \f(CW$code\fR is missing a
404 \&\*(L"Bad Request\*(R" error is reported.  The \f(CW$error_message\fR is a string that
405 is incorporated in the body of the \s-1HTML\s0 entity body.
406 .ie n .IP "$c\->send_file_response( $filename )" 4
407 .el .IP "$c\->send_file_response( \f(CW$filename\fR )" 4
408 .IX Item "$c->send_file_response( $filename )"
409 Send back a response with the specified \f(CW$filename\fR as content.  If the
410 file is a directory we try to generate an \s-1HTML\s0 index of it.
411 .ie n .IP "$c\->send_file( $filename )" 4
412 .el .IP "$c\->send_file( \f(CW$filename\fR )" 4
413 .IX Item "$c->send_file( $filename )"
414 .PD 0
415 .ie n .IP "$c\->send_file( $fd )" 4
416 .el .IP "$c\->send_file( \f(CW$fd\fR )" 4
417 .IX Item "$c->send_file( $fd )"
418 .PD
419 Copy the file to the client.  The file can be a string (which
420 will be interpreted as a filename) or a reference to an \f(CW\*(C`IO::Handle\*(C'\fR
421 or glob.
422 .IP "$c\->daemon" 4
423 .IX Item "$c->daemon"
424 Return a reference to the corresponding \f(CW\*(C`HTTP::Daemon\*(C'\fR object.
425 .SH "SEE ALSO"
426 .IX Header "SEE ALSO"
427 \&\s-1RFC\s0 2616
428 .PP
429 IO::Socket::INET, IO::Socket
430 .SH "COPYRIGHT"
431 .IX Header "COPYRIGHT"
432 Copyright 1996\-2003, Gisle Aas
433 .PP
434 This library is free software; you can redistribute it and/or
435 modify it under the same terms as Perl itself.