GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  TEST::FAKE::HTTPD (3)

.ds Aq ’

NAME

Test::Fake::HTTPD - a fake HTTP server

CONTENTS

SYNOPSIS

DSL-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 "You can connect to your server at %s.\n", $httpd->host_port;
    # or
    printf "You can connect to your server at 127.0.0.1:%d.\n", $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,
    );

    $httpd->run(sub {
        my $req = shift;
        # ...
        [ 200, [ Content-Type, text/plain ], [ Hello World ] ];
    });

    # Stop http server automatically at destruction time.



DESCRIPTION

Test::Fake::HTTPD is a fake HTTP server module for testing.

FUNCTIONS

o run_http_server { ... }

Starts HTTP server and returns the guard instance.



  my $httpd = run_http_server {
      my $req = shift;
      # ...
      return $http_or_plack_or_psgi_res;
  };

  # can use $httpd guard object, same as OO-style
  LWP::UserAgent->new->get($httpd->endpoint);



o run_https_server { ... }

Starts <B>HTTPSB> server and returns the guard instance.

If you use this method, you MUST install HTTP::Daemon::SSL.



  my $httpd = run_https_server {
      my $req = shift;
      # ...
      return $http_or_plack_or_psgi_res;
  };

  # can use $httpd guard object, same as OO-style
  my $ua = LWP::UserAgent->new(
      ssl_opts => {
          SSL_verify_mode => 0,
          verify_hostname => 0,
      },
  );
  $ua->get($httpd->endpoint);



METHODS

o new( %args )

Returns a new instance.



  my $httpd = Test::Fake::HTTPD->new(%args);



%args are:
o timeout

timeout value (default: 5)

o listen

queue size for listen (default: 5)

o port

local bind port number (default: auto detection)



  my $httpd = Test::Fake::HTTPD->new(
      timeout => 10,
      listen  => 10,
      port    => 3333,
  );



o run( sub { ... } )

Starts this HTTP server.



  $httpd->run(sub { ... });



o scheme

Returns a scheme of running, http or https.



  my $scheme = $httpd->scheme;



o port

Returns a port number of running.



  my $port = $httpd->port;



o host_port

Returns a URI host_port of running. (127.0.0.1:{port})



  my $host_port = $httpd->host_port;



o endpoint

Returns an endpoint URI of running. (http://127.0.0.1:{port} URI object)



  use LWP::UserAgent;

  my $res = LWP::UserAgent->new->get($httpd->endpoint);

  my $url = $httpd->endpoint;
  $url->path(/foo/bar);
  my $res = LWP::UserAgent->new->get($url);



AUTHOR

NAKAGAWA Masaki <masaki@cpan.org>

THANKS TO

xaicron

LICENSE

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

SEE ALSO

Test::TCP, HTTP::Daemon, HTTP::Daemon::SSL, HTTP::Message::PSGI
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 TEST::FAKE::HTTPD (3) 2015-01-25

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.