Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection: Handle IPv6 address String on #proxy_from_env #1252

Commits on Mar 22, 2021

  1. connection: Handle IPv6 address String on #proxy_from_env

    Otherwise, the following error occurs:
    
    ```log
    /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "http://::1" (URI::InvalidURIError)
    	from /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/uri/rfc3986_parser.rb:72:in `parse'
    	from /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/uri/common.rb:171:in `parse'
    	from /Users/cosmo/GitHub/faraday/lib/faraday/connection.rb:580:in `proxy_from_env'
    	from /Users/cosmo/GitHub/faraday/lib/faraday/connection.rb:100:in `initialize_proxy'
    	from /Users/cosmo/GitHub/faraday/lib/faraday/connection.rb:87:in `initialize'
    	from /Users/cosmo/GitHub/faraday/lib/faraday.rb:103:in `new'
    	from /Users/cosmo/GitHub/faraday/lib/faraday.rb:103:in `new'
    	from (irb):2:in `<main>'
    	from /Users/cosmo/GitHub/fluent-plugin-elasticsearch/vendor/bundle/ruby/3.0.0/gems/irb-1.3.4/exe/irb:11:in `<top (required)>'
    	from /Users/cosmo/GitHub/fluent-plugin-elasticsearch/vendor/bundle/ruby/3.0.0/bin/irb:23:in `load'
    	from /Users/cosmo/GitHub/fluent-plugin-elasticsearch/vendor/bundle/ruby/3.0.0/bin/irb:23:in `<top (required)>'
    	from /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'
    	from /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'
    	from /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'
    	from /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli.rb:497:in `exec'
    	from /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    	... 10 levels...
    ```
    
    This is because, in IPv6 world, URI::XXX#host and URI::XXX#hostname
    should be different:
    
    ```irb
    irb> uri = URI.parse("http://[::1]:9200")
    irb> uri.host
    => "[::1]"
    irb> uri.hostname
    => "::1"
    ```
    
    This difference causes the following invalid URI:
    
    When using `uri.host` case,
    
    ```irb
    irb> "#{uri.scheme}://#{uri.host}"
    => "http://[::1]"
    irb> URI.parse("#{uri.scheme}://#{uri.host}")
    => #<URI::HTTP http://[::1]>
    ```
    
    we got succeeded to parse created URI with `URI.parse`.
    
    When using `uri.hostname` case,
    
    ```irb
    irb> "#{uri.scheme}://#{uri.hostname}"
    => "http://::1"
    irb> > URI.parse("#{uri.scheme}://#{uri.hostname}")
    /Users/cosmo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "http://::1" (URI::InvalidURIError)
     <snip>
    ```
    
    we got failing to parse created URI with `URI.parse`.
    
    This problematic behavior breaks our use case which passes URL as IPv6
    address String.
    
    Signed-off-by: Hiroshi Hatake <cosmo0920.oucc@gmail.com>
    cosmo0920 committed Mar 22, 2021
    Copy the full SHA
    8957a43 View commit details
    Browse the repository at this point in the history