From 4629793f452c22404e75503bdaf3a5933c6843cc Mon Sep 17 00:00:00 2001 From: Tatsuhiko Miyagawa Date: Wed, 12 Jun 2013 14:21:08 -0700 Subject: [PATCH] Revert "Add HTTP::Tiny interface for LWP replacement in tests" This reverts commit e06c9423b0eb843369b0f26a8e4ab42ce2453e6d. --- cpanfile | 1 - lib/HTTP/Tiny/LWPLike.pm | 119 --------------------------------------- lib/Plack/Test/Server.pm | 8 +-- lib/Plack/Test/Suite.pm | 6 +- 4 files changed, 8 insertions(+), 126 deletions(-) delete mode 100644 lib/HTTP/Tiny/LWPLike.pm diff --git a/cpanfile b/cpanfile index e6b25eb55..13174ae53 100644 --- a/cpanfile +++ b/cpanfile @@ -14,7 +14,6 @@ requires 'Try::Tiny'; requires 'URI', '1.59'; requires 'parent'; requires 'Apache::LogFormat::Compiler', '0.12'; -requires 'HTTP::Tiny', 0.024; on test => sub { requires 'Test::More', '0.88'; diff --git a/lib/HTTP/Tiny/LWPLike.pm b/lib/HTTP/Tiny/LWPLike.pm deleted file mode 100644 index eb7462170..000000000 --- a/lib/HTTP/Tiny/LWPLike.pm +++ /dev/null @@ -1,119 +0,0 @@ -package HTTP::Tiny::LWPLike; -use strict; -use warnings; -use HTTP::Tiny; -use HTTP::Response; - -sub new { - my $class = shift; - my $self = bless {}, $class; - $self->{http} = @_ == 1 ? $_[0] : HTTP::Tiny->new(@_); - $self; -} - -sub _multiply_headers { - my($self, $headers) = @_; - - my $hdrs; - $headers->scan(sub { - if (exists $hdrs->{$_[0]}) { - push @{$hdrs->{$_[0]}}, $_[1]; - } else { - $hdrs->{$_[0]} = [ $_[1] ]; - } - }); - - while (my($k, $v) = each %$hdrs) { - $hdrs->{$k} = $v->[0] if @$v == 1; - } - - $hdrs; -} - -sub _flatten_headers { - my($self, $headers) = @_; - - my @hdrs; - while (my($k, $v) = each %$headers) { - if (ref $v eq 'ARRAY') { - push @hdrs, map { ($k => $_) } @$v; - } else { - push @hdrs, $k => $v; - } - } - - return \@hdrs; -} - -sub request { - my($self, $req) = @_; - - my $response = $self->{http}->request( - $req->method, $req->url, { - headers => $self->_multiply_headers($req->headers), - content => $req->content, - }, - ); - - my $res = HTTP::Response->new( - $response->{status}, - $response->{reason}, - $self->_flatten_headers($response->{headers}), - $response->{content}, - ); - $res->request($req); - - return $res; -} - -1; - -__END__ - -=head1 NAME - -HTTP::Tiny::LWPLike - HTTP::Request/Response compatible interface with HTTP::Tiny backend - -=head1 SYNOPSIS - - use HTTP::Tiny::LWPLike; - - my $request = HTTP::Request->new(GET => 'http://perl.com/'); - - my $ua = HTTP::Tiny::LWPLike->new; - my $res = $ua->request($request); # returns HTTP::Response - -=head1 DESCRIPTION - -This module is an adapter object that implements one method, -C that acts like L's request method -i.e. takes HTTP::Request object and returns HTTP::Response object. - -=head1 INCOMPATIBILITIES - -=over 4 - -=item * - -SSL is not supported unless required modules are installed. - -=item * - -authentication is not handled via the UA methods. You can encode the -C headers in the C<$request> by yourself. - -=cut - -There might be more - see L for the details. - -=back - -=head1 AUTHOR - -Tatsuhiko Miyagawa - -=head1 SEE ALSO - -L L - -=cut diff --git a/lib/Plack/Test/Server.pm b/lib/Plack/Test/Server.pm index 6481d9a05..843a8fb27 100644 --- a/lib/Plack/Test/Server.pm +++ b/lib/Plack/Test/Server.pm @@ -2,18 +2,18 @@ package Plack::Test::Server; use strict; use warnings; use Carp; -use HTTP::Request; -use HTTP::Response; use Test::TCP; use Plack::Loader; -use HTTP::Tiny::LWPLike; +use Test::Requires (); sub test_psgi { my %args = @_; + Test::Requires::test_requires('LWP::UserAgent'); + my $client = delete $args{client} or croak "client test code needed"; my $app = delete $args{app} or croak "app needed"; - my $ua = delete $args{ua} || HTTP::Tiny::LWPLike->new; + my $ua = delete $args{ua} || LWP::UserAgent->new; test_tcp( client => sub { diff --git a/lib/Plack/Test/Suite.pm b/lib/Plack/Test/Suite.pm index d4eca2849..7bbbe88c5 100644 --- a/lib/Plack/Test/Suite.pm +++ b/lib/Plack/Test/Suite.pm @@ -12,7 +12,7 @@ use Plack::Middleware::Lint; use Plack::Util; use Plack::Request; use Try::Tiny; -use HTTP::Tiny::LWPLike; +use Test::Requires (); my $share_dir = try { File::ShareDir::dist_dir('Plack') } || 'share'; @@ -741,6 +741,8 @@ sub runtests { sub run_server_tests { my($class, $server, $server_port, $http_port, %args) = @_; + Test::Requires::test_requires('LWP::UserAgent'); + if (ref $server ne 'CODE') { my $server_class = $server; $server = sub { @@ -755,7 +757,7 @@ sub run_server_tests { client => sub { my $port = shift; - my $ua = HTTP::Tiny::LWPLike->new; + my $ua = LWP::UserAgent->new; for my $i (0..$#TEST) { my $test = $TEST[$i]; note $test->[0];