AnyEvent-Net-Curl-Queued
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
inc/Test/HTTP/AnyEvent/Server.pm view on Meta::CPAN
1;
__END__
=pod
=encoding utf8
=head1 NAME
Test::HTTP::AnyEvent::Server - the async counterpart to Test::HTTP::Server
=head1 VERSION
version 0.007
=head1 SYNOPSIS
#!/usr/bin/env perl
use common::sense;
use AnyEvent::HTTP;
use Test::HTTP::AnyEvent::Server;
my $server = Test::HTTP::AnyEvent::Server->new;
my $cv = AE::cv;
$cv->begin;
http_request GET => $server->uri . q(echo/head), sub {
my ($body, $hdr) = @_;
say $body;
$cv->end;
};
$cv->wait;
=head1 DESCRIPTION
This package provides a simple B<NON>-forking HTTP server which can be used for testing HTTP clients.
=head1 ATTRIBUTES
=head2 address
Address to bind the server.
Defaults to C<127.0.0.1>.
=head2 port
Port to bind the server.
Picks the first available by default.
=head2 maxconn
Limit the number of accepted connections to this.
Default: 10.
=head2 timeout
Timeout connection after this number of seconds.
Default: 60.
=head2 disable_proxy
Reset the proxy-controlling environment variables (C<no_proxy>/C<http_proxy>/C<ftp_proxy>/C<all_proxy>).
I guess you don't need a proxy to connect to yourself.
Default: true.
=head2 forked
B<(experimental)> Sometimes, you just need to test some blocking code.
Setting this flag to true will start L<Test::HTTP::AnyEvent::Server> in a forked process.
=head2 forked_pid
B<(internal)> Holds the PID of a child process if L</forked> flag was used.
=head2 server
B<(internal)> Holds the guard object whose lifetime it tied to the TCP server.
=head1 METHODS
=head2 uri
Return URI of a newly created server (with a trailing C</>).
=head2 start_server($prepare_cb)
B<(internal)> Wrapper for the C<tcp_server> from L<AnyEvent::Socket>.
C<$prepare_cb> is used to get the IP address and port of the local socket endpoint and populate respective attributes.
=head1 FUNCTIONS
=head2 _cleanup
B<(internal)> Close descriptor and shutdown connection.
=head2 _reply
B<(internal)> Issue HTTP reply.
=head1 INTERFACE
Mostly borrowed from L<Test::HTTP::Server>.
=head2 GET /echo/head
Echoes back the issued HTTP request (except the content part):
$ curl -v http://127.0.0.1:44721/echo/head
* About to connect() to 127.0.0.1 port 44721 (#0)
* Trying 127.0.0.1...
* connected
* Connected to 127.0.0.1 (127.0.0.1) port 44721 (#0)
> GET /echo/head HTTP/1.1
> User-Agent: curl/7.27.0
> Host: 127.0.0.1:44721
> Accept: */*
>
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.383 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )