sergot / http-useragent

Web user agent class for Perl 6.
MIT License
36 stars 39 forks source link

Tests fail with set HTTP_PROXY #151

Closed tomk3003 closed 8 years ago

tomk3003 commented 8 years ago

If there's an HTTP_PROXY environment variable it is used for the tests with a local test server.

Patching UserAgent.pm6 like this:

(from Line 326)

multi method get-connection(HTTP::Request $request ) returns Connection {
    my $host = $request.host;
    my $port = $request.port;

    if not $host ~~ /localhost/ and self.get-proxy($request) -> $http_proxy {
        $request.file = $request.url;
        my ($proxy_host, $proxy_auth) = $http_proxy.split('/').[2].split('@', 2).reverse;
        ($host, $port) = $proxy_host.split(':');
        $port.=Int;
        if $proxy_auth.defined {
            $request.field(Proxy-Authorization => basic-auth-token($proxy_auth));
        }
        $request.field(Connection => 'close');
    }
    self.get-connection($request, $host, $port);
}

fixes the tests.

sergot commented 8 years ago

feel free to create a PR for that :))

jonathanstowe commented 8 years ago

I think it would probably be better to bring forward the no-proxy implementation I've been planning on for a while. That way we can generalise which hosts not to use the proxy without hardcoding, and use this in the tests.

I'll take a look later or tomorrow.

jonathanstowe commented 8 years ago

I can confirm this BTW (I needed to set up a proxy to test the fix I am going to make,)

jonathanstowe commented 8 years ago

That should be good now if you want to re-test