Skip to content

Twilio::HTTP::Client with proxy address and port but without user and password raises exception #435

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

Closed
simonwacker opened this issue Dec 12, 2018 · 2 comments
Labels
difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: community enhancement feature request not on Twilio's roadmap

Comments

@simonwacker
Copy link

simonwacker commented Dec 12, 2018

When you create an HTTP client with proxy address and port but without user and password, then a bad URI is supplied to Faraday's proxy on line

f.proxy "#{@proxy_user}:#{@proxy_pass}@#{@proxy_addr}:#{@proxy_port}"
The URI is of the form :@<proxy_address>:<proxy_port> but should be of the form <proxy_address>:<proxy_port>. One solution is to prepend #{@proxy_user}:#{@proxy_pass}@ only when both variables are non-nil.

Version: 5.17.0

Code Snippet

http_client = Twilio::HTTP::Client.new('62.192.192.41', 8080)
rest_client = Twilio::REST::Client.new('a', 'b', nil, nil, http_client)
rest_client.messages.create(from: 'f', to: 't', body: 'b')

Exception/Log

URI::InvalidURIError: bad URI(is not URI?): :@62.192.192.41:8080
        from /usr/local/lib/ruby/2.3.0/uri/rfc3986_parser.rb:67:in `split'
        from /usr/local/lib/ruby/2.3.0/uri/rfc3986_parser.rb:73:in `parse'
        from /usr/local/lib/ruby/2.3.0/uri/common.rb:227:in `parse'
        from /usr/local/lib/ruby/2.3.0/uri/common.rb:714:in `URI'
        from /usr/local/bundle/gems/faraday-0.9.2/lib/faraday/utils.rb:258:in `call'
        from /usr/local/bundle/gems/faraday-0.9.2/lib/faraday/utils.rb:258:in `URI'
        from /usr/local/bundle/gems/faraday-0.9.2/lib/faraday/options.rb:223:in `from'
        from /usr/local/bundle/gems/faraday-0.9.2/lib/faraday/connection.rb:286:in `proxy'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/http/http_client.rb:30:in `block in _request'
        from /usr/local/bundle/gems/faraday-0.9.2/lib/faraday/connection.rb:91:in `initialize'
        from /usr/local/bundle/gems/faraday-0.9.2/lib/faraday.rb:70:in `new'
        from /usr/local/bundle/gems/faraday-0.9.2/lib/faraday.rb:70:in `new'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/http/http_client.rb:23:in `_request'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/http/http_client.rb:56:in `request'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/rest/client.rb:78:in `request'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/framework/domain.rb:22:in `request'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/framework/version.rb:53:in `request'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/framework/version.rb:147:in `create'
        from /usr/local/bundle/gems/twilio-ruby-5.17.0/lib/twilio-ruby/rest/api/v2010/account/message.rb:131:in `create'
        from (irb):13
        from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
        from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'
        from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'
        from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

Steps to Reproduce

Paste the above code snippet into irb.

@laka3000
Copy link
Contributor

I sent a fix for this -> #445

However, I think you have to provide a scheme for you proxy path as well, since in both cases, this would result in a bad URI.

With a scheme:

Before PR

http_client = Twilio::HTTP::Client.new('http://62.192.192.41', 8080)
rest_client = Twilio::REST::Client.new('a', 'b', nil, nil, http_client)
rest_client.messages.create(from: 'f', to: 't', body: 'b')
URI::InvalidURIError: bad URI(is not URI?): :@http://62.192.192.41:8080
	from /home/kobayashi/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/uri/rfc3986_parser.rb:67:in `split'
	from /home/kobayashi/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/uri/rfc3986_parser.rb:73:in `parse'
	from /home/kobayashi/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/uri/common.rb:231:in `parse'
	from /home/kobayashi/.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/uri/common.rb:737:in `URI'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/faraday-0.15.4/lib/faraday/utils.rb:275:in `call'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/faraday-0.15.4/lib/faraday/utils.rb:275:in `URI'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/faraday-0.15.4/lib/faraday/options.rb:236:in `from'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/faraday-0.15.4/lib/faraday/connection.rb:286:in `proxy'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/http/http_client.rb:30:in `block in _request'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/faraday-0.15.4/lib/faraday/connection.rb:89:in `initialize'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/faraday-0.15.4/lib/faraday.rb:70:in `new'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/faraday-0.15.4/lib/faraday.rb:70:in `new'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/http/http_client.rb:23:in `_request'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/http/http_client.rb:56:in `request'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/rest/client.rb:80:in `request'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/framework/domain.rb:22:in `request'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/framework/version.rb:53:in `request'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/framework/version.rb:147:in `create'
	from /home/kobayashi/.rvm/gems/ruby-2.4.4/gems/twilio-ruby-5.21.1/lib/twilio-ruby/rest/api/v2010/account/message.rb:119:in `create'
	from (irb):6
	from /home/kobayashi/.rvm/rubies/ruby-2.4.4/bin/irb:11:in `<main>'

After PR (It will raise an execution expired error since, with your example, there's nowhere to connect to, but the URI is parsed correctly):

http_client = Twilio::HTTP::Client.new('http://62.192.192.41', 8080)
rest_client = Twilio::REST::Client.new('a', 'b', nil, nil, http_client)
rest_client.messages.create(from: 'f', to: 't', body: 'b')
=> Faraday::ConnectionFailed: execution expired

@childish-sambino childish-sambino added difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: community enhancement feature request not on Twilio's roadmap labels Sep 12, 2019
@childish-sambino
Copy link
Contributor

Fixed by #445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

3 participants