Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 22, 2012
@gbarr Preserve AnyEvent::HTTP pseudo heads by prefixing with X-AE- bea970d
@gbarr Fix duplicate headers in response 9162ec1
@gbarr Support proxy requests 8c5e75b
@gbarr Prevent AnyEvent::HTTP adding Referer header with the request URL fd38fb2
@gbarr Re-prime data avail condvar before waiting
If @data_queue has data before the collector is first called, then
->recv would not be called and the condvar not recreated. This meant
on the next call @data_queue was empty but the condvar was ready
resulting in undef being returned.

So we re-prime the condvar before we wait so that the condvar will
only be ready when the next chunk is placed into @data_queue
f942421
@gbarr Add git repository to dist meta 1bb46fe
View
5 Build.PL
@@ -33,6 +33,11 @@ my $build = Module::Build->new(
'version' => 0,
},
add_to_cleanup => [ 'LWP-Protocol-AnyEvent-http-*' ],
+ meta_merge => {
+ resources => {
+ repository => "http://github.com/ikegami/perl-LWP-Protocol-AnyEvent-http",
+ }
+ },
);
$build->create_build_script();
View
7 Changes.txt
@@ -1,5 +1,12 @@
Revision history for LWP-Protocol-AnyEvent-http
+1.0.4 2012-mm-dd
+ - Preserve AnyEvent::HTTP pseudo heads by prefixing with X-AE-
+ - Fix duplicate headers in response
+ - Add proxy support
+ - Prevent AnyEvent::HTTP adding Referer header with the request URL
+ - Fix bug causing cannot use undefined value as SCALAR reference
+
1.0.3 2011-06-17
- Skip tests that will fail due to DNS hijacking.
View
1  inc/Test/HTTP/LocalServer.pm
@@ -203,6 +203,7 @@ use vars qw(%urls);
'error_notfound' => 'error/notfound/%s',
'error_after_headers' => 'error/after_headers',
'chunked' => 'chunks',
+ 'referer' => 'referer',
);
for (keys %urls) {
no strict 'refs';
View
7 inc/Test/HTTP/log-server
@@ -77,6 +77,13 @@ SERVERLOOP: {
return $buf if $count-- > 0;
return undef; # done
});
+ } elsif ($location =~ m!^/referer$!) {
+ if (my $referer = $r->headers->{referer}) {
+ $res = HTTP::Response->new(302);
+ $res->header('location', $referer);
+ } else {
+ $res = HTTP::Response->new(204);
+ }
} elsif ($location =~ m!^/error/after_headers$!) {
my $count = 2;
$res = HTTP::Response->new(200, "OK", undef, sub {
View
29 lib/LWP/Protocol/AnyEvent/http.pm
@@ -27,7 +27,7 @@ sub _set_response_headers {
$response->message( delete($headers{ Reason }) );
# Uppercase headers are pseudo headers added by AnyEvent::HTTP.
- delete($headers{$_}) for grep /^[A-Z]/, keys(%headers);
+ $headers{"X-AE-$_"} = delete($headers{$_}) for grep /^(?!X-)[A-Z]/, keys(%headers);
if (exists($headers->{'set-cookie'})) {
# Set-Cookie headers are very non-standard.
@@ -38,20 +38,21 @@ sub _set_response_headers {
];
}
- $response->push_header(%headers);
+ $response->header(%headers);
}
sub request {
my ($self, $request, $proxy, $arg, $size, $timeout) = @_;
- #TODO Obey $proxy
-
my $method = $request->method();
my $url = $request->uri();
- my %headers; $request->headers()->scan(sub { $headers{$_[0]} = $_[1]; });
+ my %headers; $request->headers()->scan(sub { $headers{lc $_[0]} = $_[1]; });
my $body = $request->content_ref();
+ # Fix AnyEvent::HTTP setting Referer to the request URL
+ $headers{referer} = undef unless exists $headers{referer};
+
# The status code will be replaced.
my $response = HTTP::Response->new(599, 'Internal Server Error');
$response->request($request);
@@ -68,6 +69,11 @@ sub request {
$opts{body} = $$body if defined($body);
$opts{timeout} = $timeout if defined($timeout);
+ if ($proxy) {
+ my $proxy_uri = URI->new($proxy);
+ $opts{proxy} = [$proxy_uri->host, $proxy_uri->port, $proxy_uri->scheme];
+ }
+
# Let LWP handle redirects and cookies.
my $guard = http_request(
$method => $url,
@@ -109,11 +115,11 @@ sub request {
return $self->collect($arg, $response, sub {
if (!@data_queue) {
- # Wait for more data to arrive
- $data_avail->recv();
-
# Re-prime our channel, in case there is more.
$data_avail = AnyEvent->condvar();
+
+ # Wait for more data to arrive
+ $data_avail->recv();
};
return shift(@data_queue);
@@ -206,13 +212,6 @@ An alternative to this module. Doesn't help code that uses L<LWP::Simple> or L<L
=back
-=head1 KNOWN BUGS
-
-=head2 Ignores proxy settings
-
-I haven't gotten around to implementing proxy support.
-
-
=head1 BUGS
Please report any bugs or feature requests to C<bug-LWP-Protocol-AnyEvent-http at rt.cpan.org>,
View
4 t/04_error_404.t
@@ -35,10 +35,14 @@ my $chunk_count = 0;
my $res = $client->get("${url}error/notfound/foo", ":content_cb" => sub {
$chunk_count++
});
+
+my $date_count = () = $res->headers->as_string =~ m!^(Date:)!mig;
+
ok !$res->is_success, "The request was not successfull, as planned";
is $res->code, 404, "We caught the remote error (404)";
is $res->content, '', "We got an empty response";
is $chunk_count, 0, "We received no chunks either";
+is $date_count, 1, "Only 1 Date header in response";
undef $t; # stop the timer
View
49 t/06_referer.t
@@ -0,0 +1,49 @@
+#!perl -w
+use strict;
+use Test::More;
+
+use AnyEvent;
+use LWP::Protocol::AnyEvent::http;
+use LWP::UserAgent;
+
+# Check whether we can launch the local webserver
+if (! eval {
+ use lib '../inc', 'inc';
+ require Test::HTTP::LocalServer;
+ 1;
+}) {
+ plan skip_all => "Couldn't launch test server: $@";
+} else {
+ plan tests => 4;
+};
+
+# Launch a timer
+my $timer_events = 0;
+my $t = AnyEvent->timer(
+ after => 1, interval => 1, cb => sub { diag "Waiting for reply\n"; $timer_events++ }
+);
+
+my $client = LWP::UserAgent->new(requests_redirectable => []);
+
+my $server = Test::HTTP::LocalServer->spawn(
+ #debug => 1,
+);
+my $url = $server->url;
+diag "Retrieving URL: " . $url;
+
+my $res = $client->get($server->referer);
+is $res->code, 204, "No Referer was sent"
+ or diag($res->headers->as_string);
+
+my $referer = "http://example.com";
+$res = $client->get($server->referer, Referer => $referer);
+is $res->code, 302, "Sent Referer header";
+is $res->header('Location'), $referer, "Sent expected Referer";
+
+undef $t; # stop the timer
+
+diag "Shutting down server";
+$server->stop;
+undef $server;
+diag "Done";
+
View
49 t/07_proxy.t
@@ -0,0 +1,49 @@
+#!perl -w
+use strict;
+use Test::More;
+
+use AnyEvent;
+use LWP::Protocol::AnyEvent::http;
+use LWP::UserAgent;
+
+# Check whether we can launch the local webserver
+if (! eval {
+ use lib '../inc', 'inc';
+ require Test::HTTP::LocalServer;
+ 1;
+}) {
+ plan skip_all => "Couldn't launch test server: $@";
+} else {
+ plan tests => 4;
+};
+
+# Launch a timer
+my $timer_events = 0;
+my $t = AnyEvent->timer(
+ after => 1, interval => 1, cb => sub { diag "Waiting for reply\n"; $timer_events++ }
+);
+
+my $client = LWP::UserAgent->new();
+
+my $server = Test::HTTP::LocalServer->spawn(
+ #debug => 1,
+);
+my $url = $server->url;
+diag "Retrieving URL: " . $url;
+
+$client->proxy(http => $url);
+
+my $fetch_url = "http://no.such.domain";
+my $res = $client->get($fetch_url);
+is $res->code, 200, "Got response";
+
+is $fetch_url, $res->content, "Sent proxy requet";
+
+
+undef $t; # stop the timer
+
+diag "Shutting down server";
+$server->stop;
+undef $server;
+diag "Done";
+

No commit comments for this range

Something went wrong with that request. Please try again.