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 408 forks source link

Add option to specify ip-address. #591

Closed FiV0 closed 3 years ago

FiV0 commented 3 years ago

Is there an option to somehow specify the ip-address for a request. In Java terms I would like to do something similar to

HttpGet httpGet;
httpGet.setURI(url);
URI uri = httpGet.getURI();
HttpHost httpHost = ipAddress != null ?
    new HttpHost(InetAddress.getByAddress(ipAddress), uri.getHost(), port, scheme) :
    new HttpHost(uri.getHost(), port, scheme);
httpClient.execute(httpHost, httpGet, response -> {
        /* do something with repsonse */
    });

The main reason for this is that I do a lot of requests and would like to do dns resolving in a different thread. Let me know if you are interested in a PR and I can add something to core.clj if that is wished for. Maybe let me know what the API should look like in that case.

rymndhng commented 3 years ago

I think you can achieve this by passing in a custom :dns-resolver and implementing your own custom resolver. See https://github.com/dakrone/clj-http#dns-resolution.

FiV0 commented 3 years ago

Ah sorry. I actually saw that, but somehow thought the host-map is static. Makes sense.