Created
September 25, 2015 03:35
-
-
Save mattn/7fe2b776bba48bc20c65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/HTTP/UserAgent.pm6 b/lib/HTTP/UserAgent.pm6 | |
index d5d5da0..51d75da 100644 | |
--- a/lib/HTTP/UserAgent.pm6 | |
+++ b/lib/HTTP/UserAgent.pm6 | |
@@ -107,11 +107,17 @@ multi method request(HTTP::Request $request) { | |
my $host = $request.host; | |
my $port = $request.port; | |
+ my $proxy_auth = ''; | |
+ my $http_proxy = %*ENV<http_proxy> || %*ENV<HTTP_PROXY>; | |
- if %*ENV<http_proxy> { | |
+ if $http_proxy { | |
$request.file = "http://$host" ~ $request.file; | |
- ($host, $port) = %*ENV<http_proxy>.split('/').[2].split(':'); | |
+ ($host, $proxy_auth) = $http_proxy.split('/').[2].split('@', 2).reverse; | |
+ ($host, $port) = $host.split(':'); | |
$port.=Int; | |
+ $request.header.field( | |
+ Proxy-Authorization => "Basic " ~ MIME::Base64.encode-str($proxy_auth) | |
+ ) if $proxy_auth; | |
$request.header.field(Connection => 'close'); | |
} | |
my $conn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment