… | |
… | |
194 | |
194 | |
195 | C<$scheme> must be either missing or must be C<http> for HTTP. |
195 | C<$scheme> must be either missing or must be C<http> for HTTP. |
196 | |
196 | |
197 | If not specified, then the default proxy is used (see |
197 | If not specified, then the default proxy is used (see |
198 | C<AnyEvent::HTTP::set_proxy>). |
198 | C<AnyEvent::HTTP::set_proxy>). |
|
|
199 | |
|
|
200 | Currently, if your proxy requires authorization, you have to specify an |
|
|
201 | appropriate "Proxy-Authorization" header in every request. |
199 | |
202 | |
200 | =item body => $string |
203 | =item body => $string |
201 | |
204 | |
202 | The request body, usually empty. Will be sent as-is (future versions of |
205 | The request body, usually empty. Will be sent as-is (future versions of |
203 | this module might offer more options). |
206 | this module might offer more options). |
… | |
… | |
936 | # also, the UA should ask the user for 301 and 307 and POST, |
939 | # also, the UA should ask the user for 301 and 307 and POST, |
937 | # industry standard seems to be to simply follow. |
940 | # industry standard seems to be to simply follow. |
938 | # we go with the industry standard. 308 is defined |
941 | # we go with the industry standard. 308 is defined |
939 | # by rfc7538 |
942 | # by rfc7538 |
940 | if ($status == 301 or $status == 302 or $status == 303) { |
943 | if ($status == 301 or $status == 302 or $status == 303) { |
|
|
944 | $redirect = 1; |
941 | # HTTP/1.1 is unclear on how to mutate the method |
945 | # HTTP/1.1 is unclear on how to mutate the method |
942 | $method = "GET" unless $method eq "HEAD"; |
946 | unless ($method eq "HEAD") { |
943 | $redirect = 1; |
947 | $method = "GET"; |
|
|
948 | delete $arg{body}; |
|
|
949 | } |
944 | } elsif ($status == 307 or $status == 308) { |
950 | } elsif ($status == 307 or $status == 308) { |
945 | $redirect = 1; |
951 | $redirect = 1; |
946 | } |
952 | } |
947 | } |
953 | } |
948 | |
954 | |
… | |
… | |
1176 | |
1182 | |
1177 | # now handle proxy-CONNECT method |
1183 | # now handle proxy-CONNECT method |
1178 | if ($proxy && $uscheme eq "https") { |
1184 | if ($proxy && $uscheme eq "https") { |
1179 | # oh dear, we have to wrap it into a connect request |
1185 | # oh dear, we have to wrap it into a connect request |
1180 | |
1186 | |
|
|
1187 | my $auth = exists $hdr{"proxy-authorization"} |
|
|
1188 | ? "proxy-authorization: " . (delete $hdr{"proxy-authorization"}) . "\015\012" |
|
|
1189 | : ""; |
|
|
1190 | |
1181 | # maybe re-use $uauthority with patched port? |
1191 | # maybe re-use $uauthority with patched port? |
1182 | $state{handle}->push_write ("CONNECT $uhost:$uport HTTP/1.0\015\012\015\012"); |
1192 | $state{handle}->push_write ("CONNECT $uhost:$uport HTTP/1.0\015\012$auth\015\012"); |
1183 | $state{handle}->push_read (line => $qr_nlnl, sub { |
1193 | $state{handle}->push_read (line => $qr_nlnl, sub { |
1184 | $_[1] =~ /^HTTP\/([0-9\.]+) \s+ ([0-9]{3}) (?: \s+ ([^\015\012]*) )?/ix |
1194 | $_[1] =~ /^HTTP\/([0-9\.]+) \s+ ([0-9]{3}) (?: \s+ ([^\015\012]*) )?/ix |
1185 | or return _error %state, $cb, { @pseudo, Status => 599, Reason => "Invalid proxy connect response ($_[1])" }; |
1195 | or return _error %state, $cb, { @pseudo, Status => 599, Reason => "Invalid proxy connect response ($_[1])" }; |
1186 | |
1196 | |
1187 | if ($2 == 200) { |
1197 | if ($2 == 200) { |
… | |
… | |
1190 | } else { |
1200 | } else { |
1191 | _error %state, $cb, { @pseudo, Status => $2, Reason => $3 }; |
1201 | _error %state, $cb, { @pseudo, Status => $2, Reason => $3 }; |
1192 | } |
1202 | } |
1193 | }); |
1203 | }); |
1194 | } else { |
1204 | } else { |
|
|
1205 | delete $hdr{"proxy-authorization"} unless $proxy; |
|
|
1206 | |
1195 | $handle_actual_request->(); |
1207 | $handle_actual_request->(); |
1196 | } |
1208 | } |
1197 | }; |
1209 | }; |
1198 | |
1210 | |
1199 | _get_slot $uhost, sub { |
1211 | _get_slot $uhost, sub { |