Skip to content

Instantly share code, notes, and snippets.

@mattn
Created September 25, 2015 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/7fe2b776bba48bc20c65 to your computer and use it in GitHub Desktop.
Save mattn/7fe2b776bba48bc20c65 to your computer and use it in GitHub Desktop.
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