Skip to content

Commit

Permalink
Upgraded HttpCore to version 5.3-alpha2
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Feb 14, 2024
1 parent 661589e commit 8a7f707
Show file tree
Hide file tree
Showing 36 changed files with 105 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
package org.apache.hc.client5.http.cache;

import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;

/**
Expand Down Expand Up @@ -69,7 +68,7 @@ public static HttpCacheContext adapt(final HttpContext context) {
}

public static HttpCacheContext create() {
return new HttpCacheContext(new BasicHttpContext());
return new HttpCacheContext(new HttpClientContext());
}

public HttpCacheContext(final HttpContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import org.apache.hc.core5.http.nio.AsyncDataConsumer;
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
import org.apache.hc.core5.http.nio.CapacityChannel;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.util.Args;
Expand Down Expand Up @@ -206,8 +205,8 @@ public void execute(
public AsyncDataConsumer handleResponse(
final HttpResponse response,
final EntityDetails entityDetails) throws HttpException, IOException {
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
context.setRequest(request);
context.setResponse(response);
return asyncExecCallback.handleResponse(response, entityDetails);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
package org.apache.hc.client5.http.impl.cache;

import java.util.BitSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Expand Down Expand Up @@ -89,12 +88,12 @@ class CacheControlHeaderParser {
/**
* The set of characters that can delimit a token in the header.
*/
private static final BitSet TOKEN_DELIMS = Tokenizer.INIT_BITSET(EQUAL_CHAR, ',');
private static final Tokenizer.Delimiter TOKEN_DELIMS = Tokenizer.delimiters(EQUAL_CHAR, ',');

/**
* The set of characters that can delimit a value in the header.
*/
private static final BitSet VALUE_DELIMS = Tokenizer.INIT_BITSET(EQUAL_CHAR, ',');
private static final Tokenizer.Delimiter VALUE_DELIMS = Tokenizer.delimiters(EQUAL_CHAR, ',');

/**
* The token parser used to extract values from the header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.hc.core5.http.message.RequestLine;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.ByteArrayBuffer;
Expand Down Expand Up @@ -133,8 +132,8 @@ public ClassicHttpResponse execute(
final HttpHost target = authority != null ? new HttpHost(scheme, authority) : route.getTargetHost();
final ClassicHttpResponse response = doExecute(target, request, scope, chain);

context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
context.setRequest(request);
context.setResponse(response);

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected final void handle(
final SimpleHttpRequest request,
final AsyncServerRequestHandler.ResponseTrigger responseTrigger,
final HttpContext context) throws HttpException, IOException {
final SimpleHttpResponse response = handle(request, HttpCoreContext.adapt(context));
final SimpleHttpResponse response = handle(request, HttpCoreContext.cast(context));
final SimpleBody body = response.getBody();
final AsyncEntityProducer entityProducer;
if (body != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.net.URIAuthority;
Expand Down Expand Up @@ -207,7 +206,7 @@ protected SimpleHttpResponse handle(
connManager.setDefaultMaxPerRoute(maxConn);

// Bottom of the pool : a *keep alive* connection to Route 1.
final HttpContext context1 = new BasicHttpContext();
final HttpContext context1 = new HttpClientContext();
context1.setAttribute("user", "stuff");

final SimpleHttpRequest request1 = SimpleRequestBuilder.get()
Expand All @@ -227,7 +226,7 @@ protected SimpleHttpResponse handle(

// Send a very simple HTTP get (it MUST be simple, no auth, no proxy, no 302, no 401, ...)
// Send it to another route. Must be a keepalive.
final HttpContext context2 = new BasicHttpContext();
final HttpContext context2 = new HttpClientContext();

final SimpleHttpRequest request2 = SimpleRequestBuilder.get()
.setScheme(target.getSchemeName())
Expand All @@ -250,7 +249,7 @@ protected SimpleHttpResponse handle(
// So the ConnPoolByRoute will need to kill one connection (it is maxed out globally).
// The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
// When this happens, the RouteSpecificPool becomes empty.
final HttpContext context3 = new BasicHttpContext();
final HttpContext context3 = new HttpClientContext();

final SimpleHttpRequest request3 = SimpleRequestBuilder.get()
.setHttpHost(target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.http.io.ConnectionEndpoint;
import org.apache.hc.client5.http.io.LeaseRequest;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.testing.classic.RandomHandler;
import org.apache.hc.client5.testing.sync.extension.TestClientResources;
import org.apache.hc.core5.http.ClassicHttpRequest;
Expand All @@ -47,7 +48,6 @@
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
import org.apache.hc.core5.http.io.HttpClientConnection;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
Expand Down Expand Up @@ -128,7 +128,7 @@ public void testReleaseConnection() throws Exception {
final String uri = "/random/" + rsplen;

final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", target, uri);
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();

final LeaseRequest leaseRequest1 = connManager.lease("id1", route, null);
final ConnectionEndpoint endpoint1 = leaseRequest1.get(Timeout.ZERO_MILLISECONDS);
Expand Down Expand Up @@ -192,7 +192,7 @@ public void testReleaseConnectionWithTimeLimits() throws Exception {
final String uri = "/random/" + rsplen;

final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", target, uri);
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();

final LeaseRequest leaseRequest1 = connManager.lease("id1", route, null);
final ConnectionEndpoint endpoint1 = leaseRequest1.get(Timeout.ZERO_MILLISECONDS);
Expand Down Expand Up @@ -258,7 +258,7 @@ public void testCloseExpiredIdleConnections() throws Exception {
connManager.setMaxTotal(1);

final HttpRoute route = new HttpRoute(target, null, false);
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();

final LeaseRequest leaseRequest1 = connManager.lease("id1", route, null);
final ConnectionEndpoint endpoint1 = leaseRequest1.get(Timeout.ZERO_MILLISECONDS);
Expand Down Expand Up @@ -311,7 +311,7 @@ public void testCloseExpiredTTLConnections() throws Exception {
connManager.setMaxTotal(1);

final HttpRoute route = new HttpRoute(target, null, false);
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();

final LeaseRequest leaseRequest1 = connManager.lease("id1", route, null);
final ConnectionEndpoint endpoint1 = leaseRequest1.get(Timeout.ZERO_MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;

import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
import org.apache.hc.client5.http.ssl.HostnameVerificationPolicy;
import org.apache.hc.client5.http.ssl.HttpsSupport;
Expand All @@ -54,8 +55,6 @@
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.ssl.TrustStrategy;
Expand Down Expand Up @@ -105,7 +104,7 @@ public void testBasicSSL() throws Exception {
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
SSLTestContexts.createClientSSLContext(), hostVerifier);
Expand Down Expand Up @@ -134,7 +133,7 @@ public void testBasicDefaultHostnameVerifier() throws Exception {
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(SSLTestContexts.createClientSSLContext());
final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
try (final Socket socket = new Socket(target.getHostName(), target.getPort())) {
Expand All @@ -160,7 +159,7 @@ public void testClientAuthSSL() throws Exception {
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
SSLTestContexts.createClientSSLContext(), hostVerifier);
Expand Down Expand Up @@ -190,7 +189,7 @@ public void testClientAuthSSLFailure() throws Exception {
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
SSLTestContexts.createClientSSLContext(), hostVerifier);
Expand Down Expand Up @@ -222,7 +221,7 @@ public void testSSLTrustVerification() throws Exception {
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
// Use default SSL context
final SSLContext defaultSslContext = SSLContexts.createDefault();

Expand Down Expand Up @@ -255,7 +254,7 @@ private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();

// @formatter:off
final SSLContext sslContext = SSLContexts.custom()
Expand Down Expand Up @@ -288,7 +287,7 @@ public void testSSLDisabledByDefault() throws Exception {
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
SSLTestContexts.createClientSSLContext());
final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
Expand Down Expand Up @@ -340,7 +339,7 @@ private void testWeakCipherDisabledByDefault(final String cipherSuite) throws Ex
// @formatter:on
this.server.start();

final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
SSLTestContexts.createClientSSLContext());
final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
Expand Down Expand Up @@ -370,7 +369,7 @@ public void testHostnameVerificationClient() throws Exception {
SSLTestContexts.createClientSSLContext(),
HostnameVerificationPolicy.CLIENT,
HttpsSupport.getDefaultHostnameVerifier());
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final SSLSocket upgradedSocket = tlsStrategy.upgrade(
socket,
target1.getHostName(),
Expand All @@ -388,7 +387,7 @@ public void testHostnameVerificationClient() throws Exception {
SSLTestContexts.createClientSSLContext(),
HostnameVerificationPolicy.CLIENT,
HttpsSupport.getDefaultHostnameVerifier());
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
Assertions.assertThrows(SSLPeerUnverifiedException.class, () ->
tlsStrategy.upgrade(
socket,
Expand All @@ -403,7 +402,7 @@ public void testHostnameVerificationClient() throws Exception {
SSLTestContexts.createClientSSLContext(),
HostnameVerificationPolicy.CLIENT,
NoopHostnameVerifier.INSTANCE);
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final SSLSocket upgradedSocket = tlsStrategy.upgrade(
socket,
target1.getHostName(),
Expand Down Expand Up @@ -431,7 +430,7 @@ public void testHostnameVerificationBuiltIn() throws Exception {
SSLTestContexts.createClientSSLContext(),
HostnameVerificationPolicy.BUILTIN,
NoopHostnameVerifier.INSTANCE);
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
final SSLSocket upgradedSocket = tlsStrategy.upgrade(
socket,
target1.getHostName(),
Expand All @@ -449,7 +448,7 @@ public void testHostnameVerificationBuiltIn() throws Exception {
SSLTestContexts.createClientSSLContext(),
HostnameVerificationPolicy.BUILTIN,
NoopHostnameVerifier.INSTANCE);
final HttpContext context = new BasicHttpContext();
final HttpClientContext context = new HttpClientContext();
Assertions.assertThrows(SSLHandshakeException.class, () ->
tlsStrategy.upgrade(
socket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.apache.hc.core5.http.io.HttpRequestHandler;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.testing.classic.ClassicTestServer;
import org.apache.hc.core5.util.Timeout;
Expand Down Expand Up @@ -217,7 +216,7 @@ public void testRouteSpecificPoolRecylcing() throws Exception {
);

// Bottom of the pool : a *keep alive* connection to Route 1.
final HttpContext context1 = new BasicHttpContext();
final HttpContext context1 = new HttpClientContext();
context1.setAttribute("user", "stuff");
client.execute(target, new HttpGet("/"), context1, response -> {
EntityUtils.consume(response.getEntity());
Expand All @@ -232,7 +231,7 @@ public void testRouteSpecificPoolRecylcing() throws Exception {

// Send a very simple HTTP get (it MUST be simple, no auth, no proxy, no 302, no 401, ...)
// Send it to another route. Must be a keepalive.
final HttpContext context2 = new BasicHttpContext();
final HttpContext context2 = new HttpClientContext();
client.execute(new HttpHost("127.0.0.1", server.getPort()), new HttpGet("/"), context2, response -> {
EntityUtils.consume(response.getEntity());
return null;
Expand All @@ -248,7 +247,7 @@ public void testRouteSpecificPoolRecylcing() throws Exception {
// So the ConnPoolByRoute will need to kill one connection (it is maxed out globally).
// The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
// When this happens, the RouteSpecificPool becomes empty.
final HttpContext context3 = new BasicHttpContext();
final HttpContext context3 = new HttpClientContext();
client.execute(target, new HttpGet("/"), context3, response -> {
EntityUtils.consume(response.getEntity());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.config.Lookup;
import org.apache.hc.core5.http.protocol.BasicHttpContext;

/**
* {@link HttpClientContext} builder.
Expand Down Expand Up @@ -103,7 +102,7 @@ public ContextBuilder preemptiveBasicAuth(final HttpHost host, final UsernamePas

@Override
protected HttpClientContext createContext() {
return new HttpClientContext(new BasicHttpContext());
return new HttpClientContext();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import org.apache.hc.core5.http.nio.DataStreamChannel;
import org.apache.hc.core5.http.nio.RequestChannel;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.util.Args;
import org.slf4j.Logger;
Expand Down Expand Up @@ -442,7 +441,7 @@ public void consumeInformation(final HttpResponse httpResponse,
public void consumeResponse(final HttpResponse response,
final EntityDetails entityDetails,
final HttpContext httpContext) throws HttpException, IOException {
clientContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
clientContext.setResponse(response);
proxyHttpProcessor.process(response, entityDetails, clientContext);

final int status = response.getCode();
Expand Down Expand Up @@ -547,7 +546,7 @@ private void proceedConnected(
final EndpointInfo endpointInfo = execRuntime.getEndpointInfo();
if (endpointInfo != null) {
clientContext.setProtocolVersion(endpointInfo.getProtocol());
clientContext.setAttribute(HttpCoreContext.SSL_SESSION, endpointInfo.getSslSession());
clientContext.setSSLSession(endpointInfo.getSslSession());
}
try {
chain.proceed(request, entityProducer, scope, asyncExecCallback);
Expand Down
Loading

0 comments on commit 8a7f707

Please sign in to comment.