=pod
=encoding UTF-8
=head1 NAME
HTTP::Daemon - A simple http server class
=head1 VERSION
version 6.15
=head1 SYNOPSIS
use HTTP::Daemon; use HTTP::Status;
my $d = HTTP::Daemon->new || die; print "Please contact me at: <URL:", $d->url, ">\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { if ($r->method eq 'GET' and $r->uri->path eq "/xyzzy") {
$c->send_file_response("/etc/passwd");
}
else {
$c->send_error(RC_FORBIDDEN)
}
}
$c->close;
undef($c);
}
=head1 DESCRIPTION
Instances of the C
Please note that C
The accept() method will return when a connection from a client is
available. The returned value will be an C
This HTTP daemon does not fork(2) for you. Your application, i.e. the
user of the C
The following methods of C
=over 4
=item $d = HTTP::Daemon->new
=item $d = HTTP::Daemon->new( %opts )
The constructor method takes the same arguments as the
C
A server that wants to bind to some specific address on the standard HTTP port will be constructed like this:
$d = HTTP::Daemon->new( LocalAddr => 'www.thisplace.com', LocalPort => 80, );
See L
=item $c = $d->accept
=item $c = $d->accept( $pkg )
=item ($c, $peer_addr) = $d->accept
This method works the same as the one provided by the base class, but it
returns an C
The accept method will return C
In list context both the client object and the peer address will be
returned; see the description of the accept method of L
=item $d->url
Returns a URL string that can be used to access the server root.
=item $d->product_tokens
Returns the name that this server will use to identify itself. This
is the string that is sent with the C
The default is the string "libwww-perl-daemon/#.##" where "#.##" is replaced with the version number of this module.
=back
The C
=over 4
=item $c->get_request
=item $c->get_request( $headers_only )
This method reads data from the client and turns it into an
C
The get_request() method will normally not return until the whole request has been received from the client. This might not be what you want if the request is an upload of a large file (and with chunked transfer encoding HTTP can even support infinite request messages - uploading live audio for instance). If you pass a TRUE value as the $headers_only argument, then get_request() will return immediately after parsing the request headers and you are responsible for reading the rest of the request content. If you are going to call $c->get_request again on the same connection you better read the correct number of bytes.
=item $c->read_buffer
=item $c->read_buffer( $new_value )
Bytes read by $c->get_request, but not used are placed in the I<read buffer>. The next time $c->get_request is called it will consume the bytes in this buffer before reading more data from the network connection itself. The read buffer is invalid after $c->get_request has failed.
If you handle the reading of the request content yourself you need to empty this buffer before you read more and you need to place unconsumed bytes here. You also need this buffer if you implement services like I<101 Switching Protocols>.
This method always returns the old buffer content and can optionally replace the buffer content if you pass it an argument.
=item $c->reason
When $c->get_request returns C
=item $c->proto_ge( $proto )
Return TRUE if the client announced a protocol with version number greater or equal to the given argument. The $proto argument can be a string like "HTTP/1.1" or just "1.1".
=item $c->antique_client
Return TRUE if the client speaks the HTTP/0.9 protocol. No status code and no headers should be returned to such a client. This should be the same as !$c->proto_ge("HTTP/1.0").
=item $c->head_request
Return TRUE if the last request was a C
request. No content body must be generated for these requests.=item $c->force_last_request
Make sure that $c->get_request will not try to read more requests off this connection. If you generate a response that is not self-delimiting, then you should signal this fact by calling this method.
This attribute is turned on automatically if the client announces protocol HTTP/1.0 or worse and does not include a "Connection: Keep-Alive" header. It is also turned on automatically when HTTP/1.1 or better clients send the "Connection: close" request header.
=item $c->send_status_line
=item $c->send_status_line( $code )
=item $c->send_status_line( $code, $mess )
=item $c->send_status_line( $code, $mess, $proto )
Send the status line back to the client. If $code is omitted 200 is assumed. If $mess is omitted, then a message corresponding to $code is inserted. If $proto is missing the content of the $HTTP::Daemon::PROTO variable is used.
=item $c->send_crlf
Send the CRLF sequence to the client.
=item $c->send_basic_header
=item $c->send_basic_header( $code )
=item $c->send_basic_header( $code, $mess )
=item $c->send_basic_header( $code, $mess, $proto )
Send the status line and the "Date:" and "Server:" headers back to the client. This header is assumed to be continued and does not end with an empty CRLF line.
See the description of send_status_line() for the description of the accepted arguments.
=item $c->send_header( $field, $value )
=item $c->send_header( $field1, $value1, $field2, $value2, ... )
Send one or more header lines.
=item $c->send_response( $res )
Write an C
The content attribute of the C
=item $c->send_redirect( $loc )
=item $c->send_redirect( $loc, $code )
=item $c->send_redirect( $loc, $code, $entity_body )
Send a redirect response back to the client. The location ($loc) can be an absolute or relative URL. The $code must be one of the redirect status codes, and defaults to "301 Moved Permanently"
=item $c->send_error
=item $c->send_error( $code )
=item $c->send_error( $code, $error_message )
Send an error response back to the client. If the $code is missing a "Bad Request" error is reported. The $error_message is a string that is incorporated in the body of the HTML entity.
=item $c->send_file_response( $filename )
Send back a response with the specified $filename as content. If the file is a directory we try to generate an HTML index of it.
=item $c->send_file( $filename )
=item $c->send_file( $fd )
Copy the file to the client. The file can be a string (which
will be interpreted as a filename) or a reference to an C
=item $c->daemon
Return a reference to the corresponding C
=back
=head1 IPv6 SUPPORT
Since version 6.05, C
For some reasons, you may want to force C
use HTTP::Daemon; use Socket 'AF_INET';
my $d = HTTP::Daemon->new(Family => AF_INET);
=head1 SEE ALSO
RFC 2616
L
=head1 SUPPORT
Bugs may be submitted through Lhttps://github.com/libwww-perl/HTTP-Daemon/issues.
There is also a mailing list available for users of this distribution, at Lmailto:libwww@perl.org.
There is also an irc channel available for users of this distribution, at
L<C<#lwp> on C
=head1 AUTHOR
Gisle Aas gisle@activestate.com
=head1 CONTRIBUTORS
=for stopwords Olaf Alders Ville Skyttä Graham Knop Karen Etheridge Mark Stosberg Shoichi Kaji Chase Whitener Theo van Hoesel Slaven Rezic Petr Písař Zefram Alexey Tourbin Bron Gondwana Michal Josef Špaček Mike Schilli Tom Hukins Adam Kennedy Sjogren Alex Kapranoff amire80 Andreas J. Koenig Bill Mann Daniel Hedlund David E. Wheeler DAVIDRW Father Chrysostomos Ferenc Erki FWILES Gavin Peters Graeme Thompson Hans-H. Froehlich Ian Kilgore Jacob J jefflee john9art murphy Ondrej Hanak Perlover Peter Rabbitson phrstbrn Robert Stone Rolf Grossmann ruff sasao Sean M. Burke Spiros Denaxas Steve Hay Todd Lipcon Tony Finch Toru Yamaguchi Yuri Karaban
=over 4
=item *
Olaf Alders olaf@wundersolutions.com
=item *
Ville Skyttä ville.skytta@iki.fi
=item *
Graham Knop haarg@haarg.org
=item *
Karen Etheridge ether@cpan.org
=item *
Mark Stosberg MARKSTOS@cpan.org
=item *
Shoichi Kaji skaji@cpan.org
=item *
Chase Whitener capoeirab@cpan.org
=item *
Theo van Hoesel tvanhoesel@perceptyx.com
=item *
Slaven Rezic slaven@rezic.de
=item *
Petr Písař ppisar@redhat.com
=item *
Zefram zefram@fysh.org
=item *
Alexey Tourbin at@altlinux.ru
=item *
Bron Gondwana brong@fastmail.fm
=item *
Michal Josef Špaček mspacek@redhat.com
=item *
Mike Schilli mschilli@yahoo-inc.com
=item *
Tom Hukins tom@eborcom.com
=item *
Adam Kennedy adamk@cpan.org
=item *
Adam Sjogren asjo@koldfront.dk
=item *
Alex Kapranoff ka@nadoby.ru
=item *
amire80 amir.aharoni@gmail.com
=item *
Andreas J. Koenig andreas.koenig@anima.de
=item *
Bill Mann wfmann@alum.mit.edu
=item *
Daniel Hedlund Daniel.Hedlund@eprize.com
=item *
David E. Wheeler david@justatheory.com
=item *
DAVIDRW davidrw@cpan.org
=item *
Father Chrysostomos sprout@cpan.org
=item *
Ferenc Erki erkiferenc@gmail.com
=item *
FWILES FWILES@cpan.org
=item *
Gavin Peters gpeters@deepsky.com
=item *
Graeme Thompson Graeme.Thompson@mobilecohesion.com
=item *
Hans-H. Froehlich hfroehlich@co-de-co.de
=item *
Ian Kilgore iank@cpan.org
=item *
Jacob J waif@chaos2.org
=item *
jefflee shaohua@gmail.com
=item *
john9art john9art@yahoo.com
=item *
murphy murphy@genome.chop.edu
=item *
Ondrej Hanak ondrej.hanak@ubs.com
=item *
Perlover perlover@perlover.com
=item *
Peter Rabbitson ribasushi@cpan.org
=item *
phrstbrn phrstbrn@gmail.com
=item *
Robert Stone talby@trap.mtview.ca.us
=item *
Rolf Grossmann rg@progtech.net
=item *
ruff ruff@ukrpost.net
=item *
sasao sasao@yugen.org
=item *
Sean M. Burke sburke@cpan.org
=item *
Spiros Denaxas s.denaxas@gmail.com
=item *
Steve Hay SteveHay@planit.com
=item *
Todd Lipcon todd@amiestreet.com
=item *
Tony Finch dot@dotat.at
=item *
Toru Yamaguchi zigorou@cpan.org
=item *
Yuri Karaban tech@askold.net
=back
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 1995 by Gisle Aas.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
=cut