Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
What is the valid value format for the resolve option? #95
Curl has an option which allows me to specify to which IP a domain should be resolved
How do I set this value?
I took a look at the code but couldn't figure out how I'd have to provide the value - and the documentation on this is a bit scarce
Thanks in advance for any reply that might point me in the right direction
@tobischo thanks for asking! The libcurl docs for that option are here: http://curl.haxx.se/libcurl/c/CURLOPT_RESOLVE.html. There is currently no straight forward way to specify that in ethon.
@i0rek is there an non-straight forward way? or do you know how we can somehow manage this? net/http also doesn't seem to have such a resolve method. This resolve is quite important if you have a load-balancer behind a domain-name/dns name but want to connect to one of the servers behind the load-balancer directly. but when using https with TLSv1 and SNI (multiple ssl vhosts) you need to call that server with the correct host-name set. therefore you need to override the dns resolved name from the load-balancer IP to the host you want to connect (we need that for smoke testing the application)
any other ideas how we could manage that?
You could use
resolve = nil Ethon::Curl.slist_append(resolve, "example.com:443:18.104.22.168") e = Ethon::Easy.new(url: "https://example.com/foo", :resolve => resolve) #=> #<Ethon::Easy:0x007faca2574f30 @url="https://example.com/foo", ...>
I noticed one last gotcha: what I wrote down might leak memory. https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/header.rb#L31 prevents that. If you are going to use it you should take care of that too.
OK, after playing around a bit now I noticed that the resolve setting does not appear to be working properly
require 'ethon' resolve = nil r = "example.com:443:22.214.171.124" uri = "https://example.com/foo" Ethon::Curl.slist_append(resolve, r) e = Ethon::Easy.new(url: uri, resolve: resolve, timeout: 4) e.perform => :operation_timedout
The Ethon version resulted in a timeout from not being able to resolve it while the curl version did not have any issues and returned the expected response body.
I am using
Now I am wondering whether it is a layer 8 problem (me) or whether the issue can be found in Ethon
Well, I could upgrade my OS X...
As for reproducing the problem: you actually don't need a DNS, you just need a server with a vhost somewhere which would respond to the given domain.
Also while playing around and trying to build you a test scenario I actually noticed the mistake preventing me from a successful request:
I set up a vhost on one of my servers (which certainly would not respond when calling that domain otherwise)
Now to the mistake:
require 'ethon' resolve = nil r = "resolvetest.anotherdomain.de:80:126.96.36.199" uri = "http://resolvetest.anotherdomain.de" Ethon::Curl.slist_append(resolve, r) e = Ethon::Easy.new(url: uri, resolve: resolve, timeout: 4) e.perform
was what I tried first but I should have assigned the result from
resolve = Ethon::Curl.slist_append(nil, r)
So yeah, correct for this case would be
require 'ethon' r = "resolvetest.anotherdomain.de:80:188.8.131.52" uri = "http://resolvetest.anotherdomain.de" resolve = Ethon::Curl.slist_append(nil, r) e = Ethon::Easy.new(url: uri, resolve: resolve, timeout: 4) e.perform
Anyways, thanks for pointing me in the right direction and taking another look at it although it was just dumb luck that I noticed it now :D