cheald / manticore

Manticore is a JRuby HTTP client built on the Apache HttpClient 4.x components
https://gitlab.com/cheald/manticore
MIT License
54 stars 34 forks source link

proxy credentials aren't used when passed through the URI object #71

Closed jsvd closed 6 years ago

jsvd commented 6 years ago
jruby-9.1.12.0 :001 > require 'manticore'
 => true 
jruby-9.1.12.0 :002 > Manticore::Client.new(:proxy => 'http://a:b@localhost:8080').get("http://example.org").call
% nc -l 8080
GET http://example.org/ HTTP/1.1
Connection: Keep-Alive
Content-Length: 0
Host: example.org
Proxy-Connection: Keep-Alive
User-Agent: Manticore 0.6.1
Accept-Encoding: gzip,deflate

This seems to happen because auth_from_options is only called when either the proxy_user is explicitly set or :auth options are also passed explicitly:

auth_from_options(req, req_options, context) if req_options.key?(:auth) || proxy_user

If we relax this constraint, auth_from_options already has all the code needed to extract the user/pass from the proxy URI:

    def auth_from_options(req, options, context)
      proxy = options.fetch(:proxy, {})

      proxy_user, proxy_pass = if proxy.is_a?(String)
        proxy_uri = URI.parse(proxy)
        [proxy_uri.user, proxy_uri.password]