dakrone / clj-http

An idiomatic clojure http client wrapping the apache client. Officially supported version.
http://clojars.org/clj-http
MIT License
1.78k stars 411 forks source link

Added the ability to use a custom DNS resolver #529

Closed fhitchen closed 4 years ago

fhitchen commented 4 years ago

In the case that you are working on a server where you do not have privileges to edit the /etc/hosts file, it is useful to be able to use the custom dns resolver option supported by the apache client. It is similar to the --resolve <host:port:address[,address]...> of cUrl. It is also the only way to test virtual hosts like an OpenShift cluster where encrypted traffic is passed through proxy to the intended backend using the TLS SNI extension to determine where to route the request. To this end I added a config to the client of

:custom-dns-resolver {"foo.bar.com" [127 0 0 1]} which maps foo.bar.com to 127.0.0.1.

I only changed the BasicHttpClientConnectionManager and added an ipv4 test, and ipv6 test and a function ipv6-interfaces to test if IPV6 was available before running the ipv6 test. The function should probably be in the utils file, not the core_test.clj file.

I also added a github action (that's the workflow file) to run the tests :all on checkin. It seems to work just fine, except the null gzip test threw an EOFException. I wrapped it in a try catch block. I do not know why this was not happening previously. It throws the exception locally and in the github action.

Please let me know if this is good enough or if you would need anything else done before accepting my merge request.

fhitchen commented 4 years ago

I will close the PR after you finish with your suggestions!