--- AnyEvent-HTTP/HTTP.pm 2014/06/08 23:33:28 1.119 +++ AnyEvent-HTTP/HTTP.pm 2015/05/08 17:34:35 1.123 @@ -48,7 +48,7 @@ use base Exporter::; -our $VERSION = 2.2; +our $VERSION = 2.21; our @EXPORT = qw(http_get http_post http_head http_request); @@ -197,6 +197,9 @@ If not specified, then the default proxy is used (see C). +Currently, if your proxy requires authorization, you have to specify an +appropriate "Proxy-Authorization" header in every request. + =item body => $string The request body, usually empty. Will be sent as-is (future versions of @@ -848,7 +851,7 @@ "$method $rpath HTTP/1.1\015\012" . (join "", map "\u$_: $hdr{$_}\015\012", grep defined $hdr{$_}, keys %hdr) . "\015\012" - . (delete $arg{body}) + . $arg{body} ); # return if error occurred during push_write() @@ -936,11 +939,14 @@ # also, the UA should ask the user for 301 and 307 and POST, # industry standard seems to be to simply follow. # we go with the industry standard. 308 is defined - # by rfc7238 + # by rfc7538 if ($status == 301 or $status == 302 or $status == 303) { - # HTTP/1.1 is unclear on how to mutate the method - $method = "GET" unless $method eq "HEAD"; $redirect = 1; + # HTTP/1.1 is unclear on how to mutate the method + unless ($method eq "HEAD") { + $method = "GET"; + delete $arg{body}; + } } elsif ($status == 307 or $status == 308) { $redirect = 1; } @@ -1178,8 +1184,12 @@ if ($proxy && $uscheme eq "https") { # oh dear, we have to wrap it into a connect request + my $auth = exists $hdr{"proxy-authorization"} + ? "proxy-authorization: " . (delete $hdr{"proxy-authorization"}) . "\015\012" + : ""; + # maybe re-use $uauthority with patched port? - $state{handle}->push_write ("CONNECT $uhost:$uport HTTP/1.0\015\012\015\012"); + $state{handle}->push_write ("CONNECT $uhost:$uport HTTP/1.0\015\012$auth\015\012"); $state{handle}->push_read (line => $qr_nlnl, sub { $_[1] =~ /^HTTP\/([0-9\.]+) \s+ ([0-9]{3}) (?: \s+ ([^\015\012]*) )?/ix or return _error %state, $cb, { @pseudo, Status => 599, Reason => "Invalid proxy connect response ($_[1])" }; @@ -1192,6 +1202,8 @@ } }); } else { + delete $hdr{"proxy-authorization"} unless $proxy; + $handle_actual_request->(); } }; @@ -1279,7 +1291,7 @@ function from time to time. A cookie jar is initially an empty hash-reference that is managed by this -module. It's format is subject to change, but currently it is like this: +module. Its format is subject to change, but currently it is as follows: The key C has to contain C<1>, otherwise the hash gets emptied. All other keys are hostnames or IP addresses pointing to @@ -1334,7 +1346,7 @@ =item $AnyEvent::HTTP::MAX_PER_HOST The maximum number of concurrent connections to the same host (identified -by the hostname). If the limit is exceeded, then the additional requests +by the hostname). If the limit is exceeded, then additional requests are queued until previous connections are closed. Both persistent and non-persistent connections are counted in this limit.