Skip to content

Instantly share code, notes, and snippets.

@hamnis
Created November 21, 2013 13:48
Show Gist options
  • Save hamnis/7581821 to your computer and use it in GitHub Desktop.
Save hamnis/7581821 to your computer and use it in GitHub Desktop.
package com.example.http;
import org.apache.http.client.config.RequestConfig;
import org.codehaus.httpcache4j.HTTPHost;
public class NotRedirectingHttpClientFactory extends HttpClientFactory {
@Override
protected RequestConfig requestConfig(HTTPHost proxyHost, ConnectionConfiguration config) {
RequestConfig c = super.requestConfig(proxyHost, config);
RequestConfig.Builder builder = RequestConfig.copy(c);
builder.setRedirectsEnabled(false);
return builder.build();
}
public static CloseableHttpClient defaultClient() {
HttpClientBuilder builder = HttpClientBuilder.create();
return new NotRedirectingHttpClientFactory().configure(builder, new ResolverConfiguration());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment