|
NAMETest::Fake::HTTPD - a fake HTTP server SYNOPSISDSL-style use Test::Fake::HTTPD;
my $httpd = run_http_server {
my $req = shift;
# ...
# 1. HTTP::Response ok
return $http_response;
# 2. Plack::Response ok
return $plack_response;
# 3. PSGI response ok
return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ];
};
printf "Listening on address:port %s\n", $httpd->host_port;
# or
printf "Listening on address %s port %s\n", $httpd->host, $httpd->port;
# access to fake HTTP server
use LWP::UserAgent;
my $res = LWP::UserAgent->new->get($httpd->endpoint); # "http://127.0.0.1:{port}"
# Stop http server automatically at destruction time.
OO-style use Test::Fake::HTTPD;
my $httpd = Test::Fake::HTTPD->new(
timeout => 5,
daemon_args => { ... }, # HTTP::Daemon args
);
$httpd->run(sub {
my $req = shift;
# ...
[ 200, [ 'Content-Type', 'text/plain' ], [ 'Hello World' ] ];
});
# Stop http server automatically at destruction time.
DESCRIPTIONTest::Fake::HTTPD is a fake HTTP server module for testing. FUNCTIONS
METHODS
my $httpd = Test::Fake::HTTPD->new(
timeout => 10,
listen => 10,
port => 3333,
);
AUTHORNAKAGAWA Masaki <masaki@cpan.org> THANKS TOxaicron LICENSEThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSOTest::TCP, HTTP::Daemon, HTTP::Daemon::SSL, HTTP::Message::PSGI
|