AnyEvent-HTTPD

 view release on metacpan or  search on metacpan

lib/AnyEvent/HTTPD.pm  view on Meta::CPAN


AnyEvent::HTTPD - A simple lightweight event based web (application) server

=head1 VERSION

Version 0.93

=cut

our $VERSION = '0.93';

=head1 SYNOPSIS

    use AnyEvent::HTTPD;

    my $httpd = AnyEvent::HTTPD->new (port => 9090);

    $httpd->reg_cb (
       '/' => sub {
          my ($httpd, $req) = @_;

          $req->respond ({ content => ['text/html',
             "<html><body><h1>Hello World!</h1>"
             . "<a href=\"/test\">another test page</a>"
             . "</body></html>"
          ]});
       },
       '/test' => sub {
          my ($httpd, $req) = @_;

          $req->respond ({ content => ['text/html',
             "<html><body><h1>Test page</h1>"
             . "<a href=\"/\">Back to the main page</a>"
             . "</body></html>"
          ]});
       },
    );

    $httpd->run; # making a AnyEvent condition variable would also work

=head1 DESCRIPTION

This module provides a simple HTTPD for serving simple web application
interfaces. It's completly event based and independend from any event loop
by using the L<AnyEvent> module.

It's HTTP implementation is a bit hacky, so before using this module make sure
it works for you and the expected deployment. Feel free to improve the HTTP
support and send in patches!

The documentation is currently only the source code, but next versions of this
module will be better documented hopefully. See also the C<samples/> directory
in the L<AnyEvent::HTTPD> distribution for basic starting points.

=head1 FEATURES

=over 4

=item * support for GET and POST requests.

=item * support for HTTP 1.0 keep-alive.

=item * processing of C<x-www-form-urlencoded> and C<multipart/form-data> (C<multipart/mixed>) encoded form parameters.

=item * support for streaming responses.

=item * with version 0.8 no more dependend on L<LWP> for L<HTTP::Date>.

=item * (limited) support for SSL

=back

=head1 METHODS

The L<AnyEvent::HTTPD> class inherits directly from
L<AnyEvent::HTTPD::HTTPServer> which inherits the event callback interface from
L<Object::Event>.

Event callbacks can be registered via the L<Object::Event> API (see the
documentation of L<Object::Event> for details).

For a list of available events see below in the I<EVENTS> section.

=over 4

=item B<new (%args)>

This is the constructor for a L<AnyEvent::HTTPD> object.
The C<%args> hash may contain one of these key/value pairs:

=over 4

=item host => $host

The TCP address of the HTTP server will listen on. Usually 0.0.0.0 (the
default), for a public server, or 127.0.0.1 for a local server.

=item port => $port

The TCP port the HTTP server will listen on. If undefined some
free port will be used. You can get it via the C<port> method.

=item ssl => $tls_ctx

If this option is given the server will listen for a SSL/TLS connection on the
configured port. As C<$tls_ctx> you can pass anything that you can pass as
C<tls_ctx> to an L<AnyEvent::Handle> object.

Example:

   my $httpd =
      AnyEvent::HTTPD->new (
         port => 443,
         ssl  => { cert_file => "/path/to/my/server_cert_and_key.pem" }
      );

Or:

   my $httpd =
      AnyEvent::HTTPD->new (
         port => 443,

lib/AnyEvent/HTTPD.pm  view on Meta::CPAN

=back

=head1 CACHING

Any response from the HTTP server will have C<Cache-Control> set to C<max-age=0> and
also the C<Expires> header set to the C<Date> header. Meaning: Caching is disabled.

You can of course set those headers yourself in the response, or remove them by
setting them to undef, but keep in mind that the default for those headers are
like mentioned above.

If you need more support here you can send me a mail or even better: a patch :)

=head1 AUTHOR

Robin Redeker, C<< <elmex at ta-sa.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-bs-httpd at rt.cpan.org>,
or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-HTTPD>.  I will be
notified, and then you'll automatically be notified of progress on your bug as
I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc AnyEvent::HTTPD


You can also look for information at:

=over 4

=item * Git repository

L<http://git.ta-sa.org/AnyEvent-HTTPD.git>

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-HTTPD>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/AnyEvent-HTTPD>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/AnyEvent-HTTPD>

=item * Search CPAN

L<http://search.cpan.org/dist/AnyEvent-HTTPD>

=back

=head1 ACKNOWLEDGEMENTS

   Andrey Smirnov   - for keep-alive patches.
   Pedro Melo       - for valuable input in general and patches.
   Nicholas Harteau - patch for ';' pair separator support,
                      patch for allowed_methods support
   Chris Kastorff   - patch for making default headers removable
                      and more fault tolerant w.r.t. case.
   Mons Anderson    - Optimizing the regexes in L<AnyEvent::HTTPD::HTTPConnection>
                      and adding the C<backlog> option to L<AnyEvent::HTTPD>.

=head1 COPYRIGHT & LICENSE

Copyright 2008-2011 Robin Redeker, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


=cut

1; # End of AnyEvent::HTTPD



( run in 0.781 second using v1.01-cache-2.11-cpan-df04353d9ac )