HTTP-Engine

 view release on metacpan or  search on metacpan

lib/HTTP/Engine/Interface/ModPerl.pm  view on Meta::CPAN

    builder => 'CGI',
    writer  => {
        output_header => sub {
            my ($self, $req, $res) = @_;
            my $r = $req->_connection->{apache_request} or die "missing apache request";
            $r->status( $res->status );
            my $content_type;
            $res->headers->scan(
                sub {
                    my ($key, $val) = @_;
                    $content_type = $val if lc $key eq 'content-type';
                    $r->headers_out->add($key => $val);
                }
            );
            $r->content_type($content_type) if $content_type;
        },
        write => sub {
            my ($self, $buffer) = @_;
            $CURRENT_ENGINE->interface->apache->print( $buffer );
        },
    }

lib/HTTP/Engine/Interface/Test.pm  view on Meta::CPAN

use HTTP::Engine::Test::Request;
use Carp ();
use Encode ();

sub run {
    my ( $self, $request, %args ) = @_;
    Carp::croak('missing request object') unless $request;
    Carp::croak('incorrect request object($request->uri() returns undef)') unless $request->uri;
    if ($request->method eq 'POST') {
        Carp::carp('missing content-length header') unless defined $request->content_length;
        Carp::carp('missing content-type header') unless $request->content_type;
    }

    return $self->handle_request(
        HTTP::Engine::Test::Request->build_request_args(
            $request->uri,
            $request->content,
            {
                headers  => $request->headers,
                method   => $request->method,
                protocol => $request->protocol,

lib/HTTP/Engine/Test/Request.pm  view on Meta::CPAN

    is $req->uri, 'http://example.com/?foo=bar&bar=baz', 'uri';
    is_deeply $req->parameters, { foo => 'bar', bar => 'baz' }, 'query params';

    # use headers
    my $req = HTTP::Engine::Test::Request->new(
        uri     => 'http://example.com/',
        headers => {
            'Content-Type' => 'text/plain',
        },
    );
    is $req->header('content-type'), 'text/plain', 'content-type';

    # by HTTP::Request object
    my $req = HTTP::Engine::Test::Request->new(
        HTTP::Request->new(
            GET => 'http://example.com/?foo=bar&bar=baz',
            HTTP::Headers::Fast->new(
                'Content-Type' => 'text/plain',
            ),
        )
    );

    is $req->method, 'GET', 'GET method';
    is $req->address, '127.0.0.1', 'remote address';
    is $req->uri, 'http://example.com/?foo=bar&bar=baz', 'uri';
    is_deeply $req->parameters, { foo => 'bar', bar => 'baz' }, 'query params';
    is $req->header('content-type'), 'text/plain', 'content-type';


=head1 DESCRIPTION

HTTP::Engine::Test::Request is HTTP::Engine request object builder.

Please use in a your test.

=head1 SEE ALSO

t/020_interface/test-validation.t  view on Meta::CPAN

    )
));
check(2, HTTP::Request->new(
    POST => 'http://localhost/',
));
check(1, HTTP::Request->new(
    POST => 'http://localhost/',
    HTTP::Headers->new(
        'Content-Length' => 3,
    )
), 'missing content-type');
check(1, HTTP::Request->new(
    POST => 'http://localhost/',
    HTTP::Headers->new(
        'Content-Type' => 'text/plain',
    )
), 'missing content-length');
check(0, HTTP::Request->new(
    GET => 'http://localhost/',
));

t/050_tests/request.t  view on Meta::CPAN


# headers
do {
    my $req = HTTP::Engine::Test::Request->new(
        uri     => 'http://example.com/',
        headers => {
            'Content-Type' => 'text/plain',
        },
        method => 'GET',
    );
    is $req->header('content-type'), 'text/plain', 'content-type';
};

# upload file
do {
    my $req = HTTP::Engine::Test::Request->new(
        uri     => 'http://example.com/',
        body    => $upload_body,
        headers => {
            'Content-Type'   => 'multipart/form-data; boundary=----BOUNDARY',
            'Content-Length' => 149,

t/050_tests/request.t  view on Meta::CPAN

            HTTP::Headers::Fast->new(
                'Content-Type' => 'text/plain',
            ),
        )
    );

    is $req->method, 'GET', 'GET method';
    is $req->address, '127.0.0.1', 'remote address';
    is $req->uri, 'http://example.com/?foo=bar&bar=baz', 'uri';
    is_deeply $req->parameters, { foo => 'bar', bar => 'baz' }, 'query params';
    is $req->header('content-type'), 'text/plain', 'content-type';
};

# upload file from HTTP::Request object
do {
    my $req = HTTP::Engine::Test::Request->new(
        HTTP::Request->new(
            POST => 'http://localhost/',
            HTTP::Headers::Fast->new(
                'Content-Type'   => 'multipart/form-data; boundary=----BOUNDARY',
                'Content-Length' => 149,



( run in 2.772 seconds using v1.01-cache-2.11-cpan-524268b4103 )