Lines 42-47
Link Here
|
42 |
import java.util.function.Predicate; |
42 |
import java.util.function.Predicate; |
43 |
import java.util.regex.Pattern; |
43 |
import java.util.regex.Pattern; |
44 |
import java.util.zip.GZIPInputStream; |
44 |
import java.util.zip.GZIPInputStream; |
|
|
45 |
import java.util.zip.GZIPOutputStream; |
45 |
|
46 |
|
46 |
import javax.security.auth.Subject; |
47 |
import javax.security.auth.Subject; |
47 |
|
48 |
|
Lines 51-56
Link Here
|
51 |
import org.apache.http.HttpClientConnection; |
52 |
import org.apache.http.HttpClientConnection; |
52 |
import org.apache.http.HttpConnectionMetrics; |
53 |
import org.apache.http.HttpConnectionMetrics; |
53 |
import org.apache.http.HttpEntity; |
54 |
import org.apache.http.HttpEntity; |
|
|
55 |
import org.apache.http.HttpEntityEnclosingRequest; |
54 |
import org.apache.http.HttpException; |
56 |
import org.apache.http.HttpException; |
55 |
import org.apache.http.HttpHost; |
57 |
import org.apache.http.HttpHost; |
56 |
import org.apache.http.HttpRequest; |
58 |
import org.apache.http.HttpRequest; |
Lines 95-100
Link Here
|
95 |
import org.apache.http.conn.socket.ConnectionSocketFactory; |
97 |
import org.apache.http.conn.socket.ConnectionSocketFactory; |
96 |
import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
98 |
import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
97 |
import org.apache.http.cookie.CookieSpecProvider; |
99 |
import org.apache.http.cookie.CookieSpecProvider; |
|
|
100 |
import org.apache.http.entity.ByteArrayEntity; |
98 |
import org.apache.http.entity.ContentType; |
101 |
import org.apache.http.entity.ContentType; |
99 |
import org.apache.http.entity.FileEntity; |
102 |
import org.apache.http.entity.FileEntity; |
100 |
import org.apache.http.entity.StringEntity; |
103 |
import org.apache.http.entity.StringEntity; |
Lines 213-220
Link Here
|
213 |
} |
216 |
} |
214 |
}; |
217 |
}; |
215 |
|
218 |
|
|
|
219 |
private static final class GzipHttpRequestInterceptor implements HttpRequestInterceptor { |
220 |
@Override |
221 |
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { |
222 |
if(request instanceof HttpEntityEnclosingRequest) { |
223 |
Header header = request.getFirstHeader("Content-Encoding"); |
224 |
if(header != null && "gzip".equals(header.getValue())) { |
225 |
HttpEntityEnclosingRequest enclosingRequest = (HttpEntityEnclosingRequest) request; |
226 |
HttpEntity entity = enclosingRequest.getEntity(); |
227 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
228 |
try (GZIPOutputStream gzipOS = new GZIPOutputStream(out)) { |
229 |
entity.writeTo(gzipOS); |
230 |
} |
231 |
enclosingRequest.setEntity(new ByteArrayEntity(out.toByteArray())); |
232 |
} |
233 |
} |
234 |
} |
235 |
} |
216 |
private static final class PreemptiveAuthRequestInterceptor implements HttpRequestInterceptor { |
236 |
private static final class PreemptiveAuthRequestInterceptor implements HttpRequestInterceptor { |
217 |
//@Override |
237 |
@Override |
218 |
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { |
238 |
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { |
219 |
HttpClientContext localContext = HttpClientContext.adapt(context); |
239 |
HttpClientContext localContext = HttpClientContext.adapt(context); |
220 |
AuthManager authManager = (AuthManager) localContext.getAttribute(CONTEXT_ATTRIBUTE_AUTH_MANAGER); |
240 |
AuthManager authManager = (AuthManager) localContext.getAttribute(CONTEXT_ATTRIBUTE_AUTH_MANAGER); |
Lines 375-381
Link Here
|
375 |
|
395 |
|
376 |
private static final String DIGEST_PARAMETERS = DigestParameters.VARIABLE_NAME; |
396 |
private static final String DIGEST_PARAMETERS = DigestParameters.VARIABLE_NAME; |
377 |
|
397 |
|
378 |
|
398 |
private static final HttpRequestInterceptor GZIP_REQUEST_INTERCEPTOR = new GzipHttpRequestInterceptor(); |
379 |
private static final HttpRequestInterceptor PREEMPTIVE_AUTH_INTERCEPTOR = new PreemptiveAuthRequestInterceptor(); |
399 |
private static final HttpRequestInterceptor PREEMPTIVE_AUTH_INTERCEPTOR = new PreemptiveAuthRequestInterceptor(); |
380 |
|
400 |
|
381 |
// see https://stackoverflow.com/questions/26166469/measure-bandwidth-usage-with-apache-httpcomponents-httpclient |
401 |
// see https://stackoverflow.com/questions/26166469/measure-bandwidth-usage-with-apache-httpcomponents-httpclient |
Lines 1051-1056
Link Here
|
1051 |
} |
1071 |
} |
1052 |
builder.setDefaultCredentialsProvider(credsProvider); |
1072 |
builder.setDefaultCredentialsProvider(credsProvider); |
1053 |
} |
1073 |
} |
|
|
1074 |
builder.addInterceptorFirst(GZIP_REQUEST_INTERCEPTOR); |
1054 |
builder.disableContentCompression().addInterceptorLast(RESPONSE_CONTENT_ENCODING); |
1075 |
builder.disableContentCompression().addInterceptorLast(RESPONSE_CONTENT_ENCODING); |
1055 |
if(BASIC_AUTH_PREEMPTIVE) { |
1076 |
if(BASIC_AUTH_PREEMPTIVE) { |
1056 |
builder.addInterceptorFirst(PREEMPTIVE_AUTH_INTERCEPTOR); |
1077 |
builder.addInterceptorFirst(PREEMPTIVE_AUTH_INTERCEPTOR); |