Upgraded HttpCore to version 5.0-beta5
This commit is contained in:
parent
674df3aa9e
commit
ab7be3fd53
|
@ -163,7 +163,7 @@ public class HttpCacheEntry implements MessageHeaders, Serializable {
|
|||
* Returns all the headers that were on the origin response.
|
||||
*/
|
||||
@Override
|
||||
public Header[] getAllHeaders() {
|
||||
public Header[] getHeaders() {
|
||||
final HeaderGroup filteredHeaders = new HeaderGroup();
|
||||
for (final Iterator<Header> iterator = responseHeaders.headerIterator(); iterator.hasNext();) {
|
||||
final Header header = iterator.next();
|
||||
|
@ -171,7 +171,16 @@ public class HttpCacheEntry implements MessageHeaders, Serializable {
|
|||
filteredHeaders.addHeader(header);
|
||||
}
|
||||
}
|
||||
return filteredHeaders.getAllHeaders();
|
||||
return filteredHeaders.getHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getHeaders()}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Header[] getAllHeaders() {
|
||||
return getHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,16 +227,34 @@ public class HttpCacheEntry implements MessageHeaders, Serializable {
|
|||
* @since 5.0
|
||||
*/
|
||||
@Override
|
||||
public int countHeaders(final String name) {
|
||||
return responseHeaders.countHeaders(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #countHeaders(String)}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int containsHeaders(final String name) {
|
||||
return responseHeaders.containsHeaders(name);
|
||||
return countHeaders(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.0
|
||||
*/
|
||||
@Override
|
||||
public Header getHeader(final String name) throws ProtocolException {
|
||||
return responseHeaders.getHeader(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getHeader(String)}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Header getSingleHeader(final String name) throws ProtocolException {
|
||||
return responseHeaders.getSingleHeader(name);
|
||||
return getHeader(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -454,7 +454,7 @@ class BasicHttpAsyncCache implements HttpAsyncCache {
|
|||
requestSent,
|
||||
responseReceived,
|
||||
originResponse.getCode(),
|
||||
originResponse.getAllHeaders(),
|
||||
originResponse.getHeaders(),
|
||||
content != null ? HeapResourceFactory.INSTANCE.generate(null, content.array(), 0, content.length()) : null));
|
||||
return Operations.nonCancellable();
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ class BasicHttpCache implements HttpCache {
|
|||
requestSent,
|
||||
responseReceived,
|
||||
originResponse.getCode(),
|
||||
originResponse.getAllHeaders(),
|
||||
originResponse.getHeaders(),
|
||||
content != null ? HeapResourceFactory.INSTANCE.generate(null, content.array(), 0, content.length()) : null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class CacheUpdateHandler {
|
|||
requestSent,
|
||||
responseReceived,
|
||||
originResponse.getCode(),
|
||||
originResponse.getAllHeaders(),
|
||||
originResponse.getHeaders(),
|
||||
content != null ? resourceFactory.generate(request.getRequestUri(), content.array(), 0, content.length()) : null);
|
||||
}
|
||||
|
||||
|
@ -126,17 +126,17 @@ class CacheUpdateHandler {
|
|||
src.getRequestDate(),
|
||||
src.getResponseDate(),
|
||||
src.getStatus(),
|
||||
src.getAllHeaders(),
|
||||
src.getHeaders(),
|
||||
resource,
|
||||
variantMap);
|
||||
}
|
||||
|
||||
private Header[] mergeHeaders(final HttpCacheEntry entry, final HttpResponse response) {
|
||||
if (DateUtils.isAfter(entry, response, HttpHeaders.DATE)) {
|
||||
return entry.getAllHeaders();
|
||||
return entry.getHeaders();
|
||||
}
|
||||
final HeaderGroup headerGroup = new HeaderGroup();
|
||||
headerGroup.setHeaders(entry.getAllHeaders());
|
||||
headerGroup.setHeaders(entry.getHeaders());
|
||||
// Remove cache headers that match response
|
||||
for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
|
||||
final Header responseHeader = it.next();
|
||||
|
@ -164,7 +164,7 @@ class CacheUpdateHandler {
|
|||
}
|
||||
headerGroup.addHeader(responseHeader);
|
||||
}
|
||||
return headerGroup.getAllHeaders();
|
||||
return headerGroup.getHeaders();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class CacheableRequestPolicy {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (request.containsHeaders(HeaderConstants.PRAGMA) > 0) {
|
||||
if (request.countHeaders(HeaderConstants.PRAGMA) > 0) {
|
||||
log.debug("request with Pragma header is not serveable from cache");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class CachedHttpResponseGenerator {
|
|||
final SimpleHttpResponse response = new SimpleHttpResponse(entry.getStatus());
|
||||
response.setVersion(HttpVersion.DEFAULT);
|
||||
|
||||
response.setHeaders(entry.getAllHeaders());
|
||||
response.setHeaders(entry.getHeaders());
|
||||
|
||||
if (responseShouldContainEntity(request, entry)) {
|
||||
final Resource resource = entry.getResource();
|
||||
|
|
|
@ -57,7 +57,7 @@ class ConditionalRequestBuilder<T extends HttpRequest> {
|
|||
*/
|
||||
public T buildConditionalRequest(final T request, final HttpCacheEntry cacheEntry) {
|
||||
final T newRequest = messageCopier.copy(request);
|
||||
newRequest.setHeaders(request.getAllHeaders());
|
||||
newRequest.setHeaders(request.getHeaders());
|
||||
final Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
|
||||
if (eTag != null) {
|
||||
newRequest.setHeader(HeaderConstants.IF_NONE_MATCH, eTag.getValue());
|
||||
|
@ -96,7 +96,7 @@ class ConditionalRequestBuilder<T extends HttpRequest> {
|
|||
*/
|
||||
public T buildConditionalRequestFromVariants(final T request, final Map<String, Variant> variants) {
|
||||
final T newRequest = messageCopier.copy(request);
|
||||
newRequest.setHeaders(request.getAllHeaders());
|
||||
newRequest.setHeaders(request.getHeaders());
|
||||
|
||||
// we do not support partial content so all etags are used
|
||||
final StringBuilder etags = new StringBuilder();
|
||||
|
|
|
@ -138,17 +138,17 @@ class ResponseCachingPolicy {
|
|||
}
|
||||
}
|
||||
|
||||
if (response.containsHeaders(HeaderConstants.AGE) > 1) {
|
||||
if (response.countHeaders(HeaderConstants.AGE) > 1) {
|
||||
log.debug("Multiple Age headers");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response.containsHeaders(HeaderConstants.EXPIRES) > 1) {
|
||||
if (response.countHeaders(HeaderConstants.EXPIRES) > 1) {
|
||||
log.debug("Multiple Expires headers");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response.containsHeaders(HttpHeaders.DATE) > 1) {
|
||||
if (response.countHeaders(HttpHeaders.DATE) > 1) {
|
||||
log.debug("Multiple Date headers");
|
||||
return false;
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ class ResponseCachingPolicy {
|
|||
}
|
||||
|
||||
if (sharedCache) {
|
||||
if (request.containsHeaders(HeaderConstants.AUTHORIZATION) > 0
|
||||
if (request.countHeaders(HeaderConstants.AUTHORIZATION) > 0
|
||||
&& !hasCacheControlParameterFrom(response, AUTH_CACHEABLE_PARAMS)) {
|
||||
log.debug("Request contains private credentials");
|
||||
return false;
|
||||
|
|
|
@ -199,7 +199,7 @@ public class TestHttpCacheEntry {
|
|||
new BasicHeader("Date", DateUtils.formatDate(now))
|
||||
};
|
||||
entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK, headers, mockResource);
|
||||
final Header[] result = entry.getAllHeaders();
|
||||
final Header[] result = entry.getHeaders();
|
||||
assertEquals(headers.length, result.length);
|
||||
for(int i=0; i<headers.length; i++) {
|
||||
assertEquals(headers[i], result[i]);
|
||||
|
|
|
@ -68,8 +68,8 @@ public class HttpCacheEntryMatcher extends BaseMatcher<HttpCacheEntry> {
|
|||
if (!LangUtils.equals(expectedResponseDate, otherResponseDate)) {
|
||||
return false;
|
||||
}
|
||||
final Header[] expectedHeaders = expectedValue.getAllHeaders();
|
||||
final Header[] otherHeaders = otherValue.getAllHeaders();
|
||||
final Header[] expectedHeaders = expectedValue.getHeaders();
|
||||
final Header[] otherHeaders = otherValue.getHeaders();
|
||||
if (expectedHeaders.length != otherHeaders.length) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ public class HttpTestUtils {
|
|||
* with the same canonical header values.
|
||||
*/
|
||||
public static boolean isEndToEndHeaderSubset(final HttpMessage r1, final HttpMessage r2) {
|
||||
for (final Header h : r1.getAllHeaders()) {
|
||||
for (final Header h : r1.getHeaders()) {
|
||||
if (!isHopByHopHeader(h.getName())) {
|
||||
final String r1val = getCanonicalHeaderValue(r1, h.getName());
|
||||
final String r2val = getCanonicalHeaderValue(r2, h.getName());
|
||||
|
|
|
@ -261,7 +261,7 @@ public class TestCacheUpdateHandler {
|
|||
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
|
||||
new Date(), new Date(), response);
|
||||
|
||||
final Header[] updatedHeaders = updatedEntry.getAllHeaders();
|
||||
final Header[] updatedHeaders = updatedEntry.getHeaders();
|
||||
headersContain(updatedHeaders, "Content-Encoding", "identity");
|
||||
headersNotContain(updatedHeaders, "Content-Encoding", "gzip");
|
||||
}
|
||||
|
|
|
@ -77,13 +77,13 @@ public class TestConditionalRequestBuilder {
|
|||
|
||||
Assert.assertEquals(theMethod, newRequest.getMethod());
|
||||
Assert.assertEquals(theUri, newRequest.getRequestUri());
|
||||
Assert.assertEquals(2, newRequest.getAllHeaders().length);
|
||||
Assert.assertEquals(2, newRequest.getHeaders().length);
|
||||
|
||||
Assert.assertEquals("Accept-Encoding", newRequest.getAllHeaders()[0].getName());
|
||||
Assert.assertEquals("gzip", newRequest.getAllHeaders()[0].getValue());
|
||||
Assert.assertEquals("Accept-Encoding", newRequest.getHeaders()[0].getName());
|
||||
Assert.assertEquals("gzip", newRequest.getHeaders()[0].getValue());
|
||||
|
||||
Assert.assertEquals("If-Modified-Since", newRequest.getAllHeaders()[1].getName());
|
||||
Assert.assertEquals(lastModified, newRequest.getAllHeaders()[1].getValue());
|
||||
Assert.assertEquals("If-Modified-Since", newRequest.getHeaders()[1].getName());
|
||||
Assert.assertEquals(lastModified, newRequest.getHeaders()[1].getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -133,13 +133,13 @@ public class TestConditionalRequestBuilder {
|
|||
Assert.assertEquals(theMethod, newRequest.getMethod());
|
||||
Assert.assertEquals(theUri, newRequest.getRequestUri());
|
||||
|
||||
Assert.assertEquals(3, newRequest.getAllHeaders().length);
|
||||
Assert.assertEquals(3, newRequest.getHeaders().length);
|
||||
|
||||
Assert.assertEquals("Accept-Encoding", newRequest.getAllHeaders()[0].getName());
|
||||
Assert.assertEquals("gzip", newRequest.getAllHeaders()[0].getValue());
|
||||
Assert.assertEquals("Accept-Encoding", newRequest.getHeaders()[0].getName());
|
||||
Assert.assertEquals("gzip", newRequest.getHeaders()[0].getValue());
|
||||
|
||||
Assert.assertEquals("If-None-Match", newRequest.getAllHeaders()[1].getName());
|
||||
Assert.assertEquals(theETag, newRequest.getAllHeaders()[1].getValue());
|
||||
Assert.assertEquals("If-None-Match", newRequest.getHeaders()[1].getName());
|
||||
Assert.assertEquals(theETag, newRequest.getHeaders()[1].getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -86,7 +86,7 @@ public class TestMinimalClientRequestExecution extends LocalServerTestBase {
|
|||
final HttpRequest reqWrapper = context.getRequest();
|
||||
Assert.assertNotNull(reqWrapper);
|
||||
|
||||
final Header[] headers = reqWrapper.getAllHeaders();
|
||||
final Header[] headers = reqWrapper.getHeaders();
|
||||
final Set<String> headerSet = new HashSet<>();
|
||||
for (final Header header: headers) {
|
||||
headerSet.add(header.getName().toLowerCase(Locale.ROOT));
|
||||
|
|
|
@ -88,7 +88,12 @@ public class AsyncClientHttp2ServerPush {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int capacity() {
|
||||
protected int remainingCapacity() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int capacityIncrement() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
@ -128,7 +133,12 @@ public class AsyncClientHttp2ServerPush {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int capacity() {
|
||||
protected int remainingCapacity() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int capacityIncrement() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,12 @@ public class AsyncClientHttpExchangeStreaming {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int capacity() {
|
||||
protected int remainingCapacity() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int capacityIncrement() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,12 @@ public class AsyncQuickStart {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int capacity() {
|
||||
protected int remainingCapacity() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int capacityIncrement() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -434,7 +434,7 @@ public class AsyncRequestBuilder {
|
|||
new ConfigurableHttpRequest(method, host, !TextUtils.isBlank(path) ? path : "/") :
|
||||
new ConfigurableHttpRequest(method, uri != null ? uri : URI.create("/"));
|
||||
if (this.headergroup != null) {
|
||||
request.setHeaders(this.headergroup.getAllHeaders());
|
||||
request.setHeaders(this.headergroup.getHeaders());
|
||||
}
|
||||
if (version != null) {
|
||||
request.setVersion(version);
|
||||
|
|
|
@ -280,7 +280,7 @@ public class RequestBuilder {
|
|||
headerGroup = new HeaderGroup();
|
||||
}
|
||||
headerGroup.clear();
|
||||
headerGroup.setHeaders(request.getAllHeaders());
|
||||
headerGroup.setHeaders(request.getHeaders());
|
||||
|
||||
parameters = null;
|
||||
entity = null;
|
||||
|
@ -483,7 +483,7 @@ public class RequestBuilder {
|
|||
final HttpUriRequestBase result = new HttpUriRequestBase(method, uriNotNull);
|
||||
result.setVersion(this.version != null ? this.version : HttpVersion.HTTP_1_1);
|
||||
if (this.headerGroup != null) {
|
||||
result.setHeaders(this.headerGroup.getAllHeaders());
|
||||
result.setHeaders(this.headerGroup.getHeaders());
|
||||
}
|
||||
result.setEntity(entityCopy);
|
||||
result.setConfig(this.config);
|
||||
|
|
|
@ -143,7 +143,7 @@ public final class AsyncRedirectExec implements AsyncExecChainHandler {
|
|||
case HttpStatus.SC_SEE_OTHER:
|
||||
if (!StandardMethods.isSafe(request.getMethod())) {
|
||||
final HttpRequest httpGet = new BasicHttpRequest(StandardMethods.GET.name(), redirectUri);
|
||||
httpGet.setHeaders(scope.originalRequest.getAllHeaders());
|
||||
httpGet.setHeaders(scope.originalRequest.getHeaders());
|
||||
state.currentRequest = httpGet;
|
||||
state.currentEntityProducer = null;
|
||||
break;
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.apache.hc.core5.http2.HttpVersionPolicy;
|
|||
import org.apache.hc.core5.io.CloseMode;
|
||||
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
class InternalHttpAsyncExecRuntime implements AsyncExecRuntime {
|
||||
|
@ -190,7 +191,7 @@ class InternalHttpAsyncExecRuntime implements AsyncExecRuntime {
|
|||
return Operations.nonCancellable();
|
||||
}
|
||||
final RequestConfig requestConfig = context.getRequestConfig();
|
||||
final TimeValue timeout = requestConfig.getConnectionTimeout();
|
||||
final Timeout timeout = requestConfig.getConnectionTimeout();
|
||||
return Operations.cancellable(manager.connect(
|
||||
endpoint,
|
||||
connectionInitiator,
|
||||
|
@ -202,7 +203,7 @@ class InternalHttpAsyncExecRuntime implements AsyncExecRuntime {
|
|||
@Override
|
||||
public void completed(final AsyncConnectionEndpoint endpoint) {
|
||||
if (TimeValue.isPositive(timeout)) {
|
||||
endpoint.setSocketTimeout(timeout.toMillisIntBound());
|
||||
endpoint.setSocketTimeout(timeout);
|
||||
}
|
||||
callback.completed(InternalHttpAsyncExecRuntime.this);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
|
|||
import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
|
||||
import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
|
||||
import org.apache.hc.core5.reactor.ssl.TlsDetails;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
class LoggingIOSession implements ProtocolIOSession {
|
||||
|
@ -184,21 +185,21 @@ class LoggingIOSession implements ProtocolIOSession {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSocketTimeoutMillis() {
|
||||
return this.session.getSocketTimeoutMillis();
|
||||
public Timeout getSocketTimeout() {
|
||||
return this.session.getSocketTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSocketTimeoutMillis(final int timeout) {
|
||||
public void setSocketTimeout(final Timeout timeout) {
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug(this.id + " " + this.session + ": Set timeout " + timeout);
|
||||
}
|
||||
this.session.setSocketTimeoutMillis(timeout);
|
||||
this.session.setSocketTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastReadTimeMillis() {
|
||||
return this.session.getLastReadTimeMillis();
|
||||
public long getLastReadTime() {
|
||||
return this.session.getLastReadTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -424,6 +424,11 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
|
|||
return released.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return !isReleased() && connectionEndpoint.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(
|
||||
final AsyncClientExchangeHandler exchangeHandler,
|
||||
|
|
|
@ -93,9 +93,18 @@ public final class CloseableHttpResponse implements ClassicHttpResponse {
|
|||
return response.getReasonPhrase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #countHeaders(String)}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int containsHeaders(final String name) {
|
||||
return response.containsHeaders(name);
|
||||
return countHeaders(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countHeaders(final String name) {
|
||||
return response.countHeaders(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,9 +147,18 @@ public final class CloseableHttpResponse implements ClassicHttpResponse {
|
|||
response.setLocale(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getHeader(String)}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Header getSingleHeader(final String name) throws ProtocolException {
|
||||
return response.getSingleHeader(name);
|
||||
return getHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header getHeader(final String name) throws ProtocolException {
|
||||
return response.getHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -178,9 +196,18 @@ public final class CloseableHttpResponse implements ClassicHttpResponse {
|
|||
return response.getLastHeader(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getHeaders()}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Header[] getAllHeaders() {
|
||||
return response.getAllHeaders();
|
||||
return getHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Header[] getHeaders() {
|
||||
return response.getHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -149,10 +149,10 @@ class InternalExecRuntime implements ExecRuntime, Cancellable {
|
|||
}
|
||||
}
|
||||
final RequestConfig requestConfig = context.getRequestConfig();
|
||||
final TimeValue timeout = requestConfig.getConnectionTimeout();
|
||||
final Timeout timeout = requestConfig.getConnectionTimeout();
|
||||
manager.connect(endpoint, timeout, context);
|
||||
if (TimeValue.isPositive(timeout)) {
|
||||
endpoint.setSocketTimeout(timeout.toMillisIntBound());
|
||||
endpoint.setSocketTimeout(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ public final class RedirectExec implements ExecChainHandler {
|
|||
case HttpStatus.SC_SEE_OTHER:
|
||||
if (!StandardMethods.isSafe(request.getMethod())) {
|
||||
final HttpGet httpGet = new HttpGet(redirectUri);
|
||||
httpGet.setHeaders(originalRequest.getAllHeaders());
|
||||
httpGet.setHeaders(originalRequest.getHeaders());
|
||||
redirect = httpGet;
|
||||
} else {
|
||||
redirect = null;
|
||||
|
|
|
@ -413,8 +413,8 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setSocketTimeout(final int timeout) {
|
||||
getValidatedConnection().setSocketTimeoutMillis(timeout);
|
||||
public void setSocketTimeout(final Timeout timeout) {
|
||||
getValidatedConnection().setSocketTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.apache.hc.core5.http.message.RequestLine;
|
|||
import org.apache.hc.core5.http.message.StatusLine;
|
||||
import org.apache.hc.core5.io.CloseMode;
|
||||
import org.apache.hc.core5.util.Identifiable;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -64,7 +65,7 @@ final class DefaultManagedHttpClientConnection
|
|||
private final String id;
|
||||
private final AtomicBoolean closed;
|
||||
|
||||
private int socketTimeout;
|
||||
private Timeout socketTimeout;
|
||||
|
||||
public DefaultManagedHttpClientConnection(
|
||||
final String id,
|
||||
|
@ -98,7 +99,7 @@ final class DefaultManagedHttpClientConnection
|
|||
throw new InterruptedIOException("Connection already shutdown");
|
||||
}
|
||||
super.bind(socketHolder);
|
||||
socketTimeout = socketHolder.getSocket().getSoTimeout();
|
||||
socketTimeout = Timeout.ofMillis(socketHolder.getSocket().getSoTimeout());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,11 +129,11 @@ final class DefaultManagedHttpClientConnection
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setSocketTimeoutMillis(final int timeout) {
|
||||
public void setSocketTimeout(final Timeout timeout) {
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug(this.id + ": set socket timeout to " + timeout);
|
||||
}
|
||||
super.setSocketTimeoutMillis(timeout);
|
||||
super.setSocketTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,14 +149,14 @@ final class DefaultManagedHttpClientConnection
|
|||
@Override
|
||||
public void bind(final Socket socket) throws IOException {
|
||||
super.bind(this.wireLog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id, this.wireLog) : new SocketHolder(socket));
|
||||
socketTimeout = socket.getSoTimeout();
|
||||
socketTimeout = Timeout.ofMillis(socket.getSoTimeout());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResponseReceived(final ClassicHttpResponse response) {
|
||||
if (response != null && this.headerLog.isDebugEnabled()) {
|
||||
this.headerLog.debug(this.id + " << " + new StatusLine(response));
|
||||
final Header[] headers = response.getAllHeaders();
|
||||
final Header[] headers = response.getHeaders();
|
||||
for (final Header header : headers) {
|
||||
this.headerLog.debug(this.id + " << " + header.toString());
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ final class DefaultManagedHttpClientConnection
|
|||
protected void onRequestSubmitted(final ClassicHttpRequest request) {
|
||||
if (request != null && this.headerLog.isDebugEnabled()) {
|
||||
this.headerLog.debug(this.id + " >> " + new RequestLine(request));
|
||||
final Header[] headers = request.getAllHeaders();
|
||||
final Header[] headers = request.getHeaders();
|
||||
for (final Header header : headers) {
|
||||
this.headerLog.debug(this.id + " >> " + header.toString());
|
||||
}
|
||||
|
@ -175,12 +176,12 @@ final class DefaultManagedHttpClientConnection
|
|||
|
||||
@Override
|
||||
public void passivate() {
|
||||
super.setSocketTimeoutMillis(0);
|
||||
super.setSocketTimeout(Timeout.ZERO_MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
super.setSocketTimeoutMillis(socketTimeout);
|
||||
super.setSocketTimeout(socketTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -547,8 +547,8 @@ public class PoolingHttpClientConnectionManager
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setSocketTimeout(final int timeout) {
|
||||
getValidatedPoolEntry().getConnection().setSocketTimeoutMillis(timeout);
|
||||
public void setSocketTimeout(final Timeout timeout) {
|
||||
getValidatedPoolEntry().getConnection().setSocketTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
|
|||
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
||||
import org.apache.hc.core5.reactor.IOSession;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectionOperator {
|
||||
|
||||
|
@ -68,7 +68,7 @@ final class DefaultAsyncClientConnectionOperator implements AsyncClientConnectio
|
|||
final ConnectionInitiator connectionInitiator,
|
||||
final HttpHost host,
|
||||
final SocketAddress localAddress,
|
||||
final TimeValue connectTimeout,
|
||||
final Timeout connectTimeout,
|
||||
final Object attachment,
|
||||
final FutureCallback<ManagedAsyncClientConnection> callback) {
|
||||
Args.notNull(connectionInitiator, "Connection initiator");
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
|
|||
import org.apache.hc.core5.reactor.ssl.TlsDetails;
|
||||
import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
|
||||
import org.apache.hc.core5.util.Identifiable;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -61,12 +62,12 @@ final class DefaultManagedAsyncClientConnection implements ManagedAsyncClientCon
|
|||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final IOSession ioSession;
|
||||
private final int socketTimeout;
|
||||
private final Timeout socketTimeout;
|
||||
private final AtomicBoolean closed;
|
||||
|
||||
public DefaultManagedAsyncClientConnection(final IOSession ioSession) {
|
||||
this.ioSession = ioSession;
|
||||
this.socketTimeout = ioSession.getSocketTimeoutMillis();
|
||||
this.socketTimeout = ioSession.getSocketTimeout();
|
||||
this.closed = new AtomicBoolean();
|
||||
}
|
||||
|
||||
|
@ -101,13 +102,13 @@ final class DefaultManagedAsyncClientConnection implements ManagedAsyncClientCon
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setSocketTimeoutMillis(final int timeout) {
|
||||
ioSession.setSocketTimeoutMillis(timeout);
|
||||
public void setSocketTimeout(final Timeout timeout) {
|
||||
ioSession.setSocketTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSocketTimeoutMillis() {
|
||||
return ioSession.getSocketTimeoutMillis();
|
||||
public Timeout getSocketTimeout() {
|
||||
return ioSession.getSocketTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -180,12 +181,12 @@ final class DefaultManagedAsyncClientConnection implements ManagedAsyncClientCon
|
|||
|
||||
@Override
|
||||
public void passivate() {
|
||||
ioSession.setSocketTimeoutMillis(0);
|
||||
ioSession.setSocketTimeout(Timeout.ZERO_MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
ioSession.setSocketTimeoutMillis(socketTimeout);
|
||||
ioSession.setSocketTimeout(socketTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.hc.core5.concurrent.FutureCallback;
|
|||
import org.apache.hc.core5.net.NamedEndpoint;
|
||||
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
||||
import org.apache.hc.core5.reactor.IOSession;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
final class MultihomeIOSessionRequester {
|
||||
|
||||
|
@ -58,7 +58,7 @@ final class MultihomeIOSessionRequester {
|
|||
final NamedEndpoint remoteEndpoint,
|
||||
final SocketAddress remoteAddress,
|
||||
final SocketAddress localAddress,
|
||||
final TimeValue connectTimeout,
|
||||
final Timeout connectTimeout,
|
||||
final Object attachment,
|
||||
final FutureCallback<IOSession> callback) {
|
||||
if (remoteAddress != null) {
|
||||
|
@ -128,7 +128,7 @@ final class MultihomeIOSessionRequester {
|
|||
final ConnectionInitiator connectionInitiator,
|
||||
final NamedEndpoint remoteEndpoint,
|
||||
final SocketAddress localAddress,
|
||||
final TimeValue connectTimeout,
|
||||
final Timeout connectTimeout,
|
||||
final Object attachment,
|
||||
final FutureCallback<IOSession> callback) {
|
||||
return connect(connectionInitiator, remoteEndpoint, null, localAddress, connectTimeout, attachment, callback);
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.hc.core5.net.NamedEndpoint;
|
|||
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
||||
import org.apache.hc.core5.reactor.IOSession;
|
||||
import org.apache.hc.core5.util.Args;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
/**
|
||||
* Multi-home DNS aware implementation of {@link ConnectionInitiator}.
|
||||
|
@ -63,7 +63,7 @@ public final class MultuhomeConnectionInitiator implements ConnectionInitiator {
|
|||
final NamedEndpoint remoteEndpoint,
|
||||
final SocketAddress remoteAddress,
|
||||
final SocketAddress localAddress,
|
||||
final TimeValue connectTimeout,
|
||||
final Timeout connectTimeout,
|
||||
final Object attachment,
|
||||
final FutureCallback<IOSession> callback) {
|
||||
Args.notNull(remoteEndpoint, "Remote endpoint");
|
||||
|
@ -73,7 +73,7 @@ public final class MultuhomeConnectionInitiator implements ConnectionInitiator {
|
|||
public Future<IOSession> connect(
|
||||
final NamedEndpoint remoteEndpoint,
|
||||
final SocketAddress localAddress,
|
||||
final TimeValue connectTimeout,
|
||||
final Timeout connectTimeout,
|
||||
final Object attachment,
|
||||
final FutureCallback<IOSession> callback) {
|
||||
Args.notNull(remoteEndpoint, "Remote endpoint");
|
||||
|
|
|
@ -335,7 +335,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
|
|||
public Future<AsyncConnectionEndpoint> connect(
|
||||
final AsyncConnectionEndpoint endpoint,
|
||||
final ConnectionInitiator connectionInitiator,
|
||||
final TimeValue timeout,
|
||||
final Timeout timeout,
|
||||
final Object attachment,
|
||||
final HttpContext context,
|
||||
final FutureCallback<AsyncConnectionEndpoint> callback) {
|
||||
|
@ -539,8 +539,8 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setSocketTimeout(final int timeout) {
|
||||
getValidatedPoolEntry().getConnection().setSocketTimeoutMillis(timeout);
|
||||
public void setSocketTimeout(final Timeout timeout) {
|
||||
getValidatedPoolEntry().getConnection().setSocketTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.hc.core5.http.HttpException;
|
|||
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.hc.core5.io.ModalCloseable;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
/**
|
||||
* Client endpoint leased from a connection manager. Client points can be used
|
||||
|
@ -75,6 +76,6 @@ public abstract class ConnectionEndpoint implements ModalCloseable {
|
|||
*
|
||||
* @param timeout timeout value
|
||||
*/
|
||||
public abstract void setSocketTimeout(int timeout);
|
||||
public abstract void setSocketTimeout(Timeout timeout);
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public interface AsyncClientConnectionManager extends ModalCloseable {
|
|||
* {@link AsyncConnectionEndpoint#isConnected() disconnected}. The consumer
|
||||
* of the endpoint is responsible for fully establishing the route to
|
||||
* the endpoint target by calling {@link #connect(AsyncConnectionEndpoint,
|
||||
* ConnectionInitiator, TimeValue, Object, HttpContext, FutureCallback)}
|
||||
* ConnectionInitiator, Timeout, Object, HttpContext, FutureCallback)}
|
||||
* in order to connect directly to the target or to the first proxy hop,
|
||||
* and optionally calling {@link #upgrade(AsyncConnectionEndpoint, Object, HttpContext)}
|
||||
* method to upgrade the underlying transport to Transport Layer Security
|
||||
|
@ -112,7 +112,7 @@ public interface AsyncClientConnectionManager extends ModalCloseable {
|
|||
Future<AsyncConnectionEndpoint> connect(
|
||||
AsyncConnectionEndpoint endpoint,
|
||||
ConnectionInitiator connectionInitiator,
|
||||
TimeValue connectTimeout,
|
||||
Timeout connectTimeout,
|
||||
Object attachment,
|
||||
HttpContext context,
|
||||
FutureCallback<AsyncConnectionEndpoint> callback);
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
|
|||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.reactor.ConnectionInitiator;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
/**
|
||||
* Connection operator that performs connection connect and upgrade operations.
|
||||
|
@ -63,7 +63,7 @@ public interface AsyncClientConnectionOperator {
|
|||
ConnectionInitiator connectionInitiator,
|
||||
HttpHost host,
|
||||
SocketAddress localAddress,
|
||||
TimeValue connectTimeout,
|
||||
Timeout connectTimeout,
|
||||
Object attachment,
|
||||
FutureCallback<ManagedAsyncClientConnection> callback);
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
|||
import org.apache.hc.core5.http.protocol.HttpCoreContext;
|
||||
import org.apache.hc.core5.io.CloseMode;
|
||||
import org.apache.hc.core5.io.ModalCloseable;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
/**
|
||||
* Client connection endpoint that can be used to execute message exchanges.
|
||||
|
@ -75,7 +76,7 @@ public abstract class AsyncConnectionEndpoint implements ModalCloseable {
|
|||
*
|
||||
* @param timeout the socket timeout.
|
||||
*/
|
||||
public abstract void setSocketTimeout(int timeout);
|
||||
public abstract void setSocketTimeout(Timeout timeout);
|
||||
|
||||
@Override
|
||||
public final void close() throws IOException {
|
||||
|
|
|
@ -273,8 +273,8 @@ public class TestInternalExecRuntime {
|
|||
|
||||
execRuntime.connectEndpoint(context);
|
||||
|
||||
Mockito.verify(mgr).connect(connectionEndpoint, TimeValue.ofMillis(123), context);
|
||||
Mockito.verify(connectionEndpoint).setSocketTimeout(123);
|
||||
Mockito.verify(mgr).connect(connectionEndpoint, Timeout.ofMillis(123), context);
|
||||
Mockito.verify(connectionEndpoint).setSocketTimeout(Timeout.ofMillis(123));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -88,7 +88,7 @@ public class TestRetryExec {
|
|||
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
|
||||
final Object[] args = invocationOnMock.getArguments();
|
||||
final ClassicHttpRequest wrapper = (ClassicHttpRequest) args[0];
|
||||
final Header[] headers = wrapper.getAllHeaders();
|
||||
final Header[] headers = wrapper.getHeaders();
|
||||
Assert.assertEquals(2, headers.length);
|
||||
Assert.assertEquals("this", headers[0].getValue());
|
||||
Assert.assertEquals("that", headers[1].getValue());
|
||||
|
|
|
@ -123,7 +123,7 @@ public class TestRequestExpectContinue {
|
|||
final ClassicHttpRequest request = new BasicClassicHttpRequest("POST", "/");
|
||||
final RequestExpectContinue interceptor = new RequestExpectContinue();
|
||||
interceptor.process(request, null, context);
|
||||
Assert.assertEquals(0, request.getAllHeaders().length);
|
||||
Assert.assertEquals(0, request.getHeaders().length);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -68,7 +68,7 @@
|
|||
<properties>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<httpcore.version>5.0-beta3</httpcore.version>
|
||||
<httpcore.version>5.0-beta5</httpcore.version>
|
||||
<log4j.version>2.9.1</log4j.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<ehcache.version>3.4.0</ehcache.version>
|
||||
|
@ -98,6 +98,11 @@
|
|||
<artifactId>httpcore5-testing</artifactId>
|
||||
<version>${httpcore.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.core5</groupId>
|
||||
<artifactId>httpcore5-reactive</artifactId>
|
||||
<version>${httpcore.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
|
Loading…
Reference in New Issue