In Apache HttpClient 4.2 one could create a DefaultHttpClient
and set a host such that those making an execute
call would not have to provide the host information in the input request URI, i.e.:
HttpHost targetHost = new HttpHost(host, port, secure ? "https" : "http");
DefaultHttpClient defaultHttp = new DefaultHttpClient(connectionManager);
defaultHttp.getParams().setParameter(ClientPNames.DEFAULT_HOST, targetHost);
I do admit this strategy appears very awkward, I inherited this code :). I'm sure there's an even better way to do this in 4.2.
I'm looking to upgrade to 4.3 and noticed that DefaultHttpClient
and ClientPNames
are now both deprecated in favor of HttpClientBuilder
and RequestConfig
respectively. However I can find no such way to define a default target with RequestConfig
.
Documentation for execute does reference that that input target parameter can accept null, so I'm sure there is still a way to facilitate this, but I'm struggling to figure this out:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.