本文整理匯總了Java中org.apache.http.impl.client.HttpClientBuilder.disableContentCompression方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientBuilder.disableContentCompression方法的具體用法?Java HttpClientBuilder.disableContentCompression怎麽用?Java HttpClientBuilder.disableContentCompression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.client.HttpClientBuilder
的用法示例。
在下文中一共展示了HttpClientBuilder.disableContentCompression方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: RequestEntityRestStorageService
import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
public RequestEntityRestStorageService(final S3Session session,
final Jets3tProperties properties,
final HttpClientBuilder configuration) {
super(session.getHost().getCredentials().isAnonymousLogin() ? null :
new AWSCredentials(null, null) {
@Override
public String getAccessKey() {
return session.getHost().getCredentials().getUsername();
}
@Override
public String getSecretKey() {
return session.getHost().getCredentials().getPassword();
}
},
new PreferencesUseragentProvider().get(), null, properties);
this.session = session;
configuration.disableContentCompression();
configuration.setRetryHandler(new S3HttpRequestRetryHandler(this, preferences.getInteger("http.connections.retry")));
configuration.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException {
if(response.containsHeader("x-amz-bucket-region")) {
final String host = ((HttpUriRequest) request).getURI().getHost();
if(!StringUtils.equals(session.getHost().getHostname(), host)) {
regionEndpointCache.putRegionForBucketName(
StringUtils.split(StringUtils.removeEnd(((HttpUriRequest) request).getURI().getHost(), session.getHost().getHostname()), ".")[0],
response.getFirstHeader("x-amz-bucket-region").getValue());
}
}
return super.getRedirect(request, response, context);
}
});
this.setHttpClient(configuration.build());
}
示例2: connect
import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
@Override
public Client connect(final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException {
// Always inject new pool to builder on connect because the pool is shutdown on disconnect
final HttpClientBuilder pool = builder.build(this, prompt);
pool.disableContentCompression();
return new Client(pool.build());
}
示例3: build
import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
/**
* @param listener Log listener
* @param prompt Prompt for proxy credentials
* @return Builder for HTTP client
*/
public HttpClientBuilder build(final TranscriptListener listener, final LoginCallback prompt) {
final HttpClientBuilder configuration = HttpClients.custom();
// Use HTTP Connect proxy implementation provided here instead of
// relying on internal proxy support in socket factory
final Proxy proxy = proxyFinder.find(host);
switch(proxy.getType()) {
case HTTP:
case HTTPS:
final HttpHost h = new HttpHost(proxy.getHostname(), proxy.getPort(), StringUtils.lowerCase(proxy.getType().name()));
if(log.isInfoEnabled()) {
log.info(String.format("Setup proxy %s", h));
}
configuration.setProxy(h);
configuration.setProxyAuthenticationStrategy(new CallbackProxyAuthenticationStrategy(ProxyCredentialsStoreFactory.get(), host, prompt));
break;
}
configuration.setUserAgent(new PreferencesUseragentProvider().get());
final int timeout = preferences.getInteger("connection.timeout.seconds") * 1000;
configuration.setDefaultSocketConfig(SocketConfig.custom()
.setTcpNoDelay(true)
.setSoTimeout(timeout)
.build());
configuration.setDefaultRequestConfig(this.createRequestConfig(timeout));
final String encoding;
if(null == host.getEncoding()) {
encoding = preferences.getProperty("browser.charset.encoding");
}
else {
encoding = host.getEncoding();
}
configuration.setDefaultConnectionConfig(ConnectionConfig.custom()
.setBufferSize(preferences.getInteger("http.socket.buffer"))
.setCharset(Charset.forName(encoding))
.build());
if(preferences.getBoolean("http.connections.reuse")) {
configuration.setConnectionReuseStrategy(new DefaultClientConnectionReuseStrategy());
}
else {
configuration.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
}
configuration.setRetryHandler(new ExtendedHttpRequestRetryHandler(preferences.getInteger("http.connections.retry")));
configuration.setServiceUnavailableRetryStrategy(new DisabledServiceUnavailableRetryStrategy());
if(!preferences.getBoolean("http.compression.enable")) {
configuration.disableContentCompression();
}
configuration.setRequestExecutor(new LoggingHttpRequestExecutor(listener));
// Always register HTTP for possible use with proxy. Contains a number of protocol properties such as the
// default port and the socket factory to be used to create the java.net.Socket instances for the given protocol
configuration.setConnectionManager(this.createConnectionManager(this.createRegistry()));
configuration.setDefaultAuthSchemeRegistry(RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.BASIC, new BasicSchemeFactory(
Charset.forName(preferences.getProperty("http.credentials.charset"))))
.register(AuthSchemes.DIGEST, new DigestSchemeFactory(
Charset.forName(preferences.getProperty("http.credentials.charset"))))
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build());
return configuration;
}
示例4: create
import org.apache.http.impl.client.HttpClientBuilder; //導入方法依賴的package包/類
@Override
public ConnectionManagerAwareHttpClient create(HttpClientSettings settings) {
final HttpClientBuilder builder = HttpClients.custom();
// Note that it is important we register the original connection manager with the
// IdleConnectionReaper as it's required for the successful deregistration of managers
// from the reaper. See https://github.com/aws/aws-sdk-java/issues/722.
final HttpClientConnectionManager cm = cmFactory.create(settings);
builder.setRequestExecutor(new SdkHttpRequestExecutor())
.setKeepAliveStrategy(buildKeepAliveStrategy(settings))
.disableRedirectHandling()
.disableAutomaticRetries()
.setConnectionManager(ClientConnectionManagerFactory.wrap(cm));
// By default http client enables Gzip compression. So we disable it
// here.
// Apache HTTP client removes Content-Length, Content-Encoding and
// Content-MD5 headers when Gzip compression is enabled. Currently
// this doesn't affect S3 or Glacier which exposes these headers.
//
if (!(settings.useGzip())) {
builder.disableContentCompression();
}
HttpResponseInterceptor itcp = new CRC32ChecksumResponseInterceptor();
if (settings.calculateCRC32FromCompressedData()) {
builder.addInterceptorFirst(itcp);
} else {
builder.addInterceptorLast(itcp);
}
addProxyConfig(builder, settings);
final ConnectionManagerAwareHttpClient httpClient = new SdkHttpClient(builder.build(), cm);
if (settings.useReaper()) {
IdleConnectionReaper.registerConnectionManager(cm, settings.getMaxIdleConnectionTime());
}
return httpClient;
}