From 4dc82b40f6cc0ff760b77fdc5bbdc4f4b3a401e9 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 23 Dec 2023 13:16:25 +0100 Subject: [PATCH] Removed references to deprecated functions --- .../http/impl/cache/AsyncCachingExec.java | 3 +- .../http/impl/cache/CacheKeyGenerator.java | 2 +- .../client5/http/impl/cache/CachingExec.java | 5 ++- .../impl/cache/ConditionalRequestBuilder.java | 6 ++-- .../cache/TestConditionalRequestBuilder.java | 5 ++- .../testing/sync/TestSSLSocketFactory.java | 14 +------- .../hc/client5/http/impl/RequestSupport.java | 2 +- .../impl/classic/ContentCompressionExec.java | 14 ++++---- .../io/DefaultHttpResponseParserFactory.java | 32 +++++++++++++++++-- .../impl/io/LenientHttpResponseParser.java | 2 +- .../ManagedHttpClientConnectionFactory.java | 4 +-- .../http/examples/ClientConfiguration.java | 15 +++++---- .../http/impl/auth/TestBasicScheme.java | 2 +- 13 files changed, 63 insertions(+), 43 deletions(-) diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java index d994d4a73..41fc2c368 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java @@ -30,6 +30,7 @@ import java.io.InterruptedIOException; import java.nio.ByteBuffer; import java.time.Instant; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -1127,7 +1128,7 @@ void negotiateResponseFromVariants( } final HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants( BasicRequestBuilder.copy(request).build(), - variantMap.keySet()); + new ArrayList<>(variantMap.keySet())); final Instant requestDate = getCurrentDate(); chainProceed(conditionalRequest, entityProducer, scope, chain, new AsyncExecCallback() { diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java index 9e68de815..be346370e 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java @@ -143,7 +143,7 @@ public static URI normalize(final URI requestUri) throws URISyntaxException { } } builder.setFragment(null); - return builder.normalizeSyntax().build(); + return builder.optimize().build(); } /** diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java index 7a42731e1..c83ac89fd 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.InputStream; import java.time.Instant; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -583,7 +584,9 @@ ClassicHttpResponse negotiateResponseFromVariants( } } - final ClassicHttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants(request, variantMap.keySet()); + final ClassicHttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants( + request, + new ArrayList<>(variantMap.keySet())); final Instant requestDate = getCurrentDate(); final ClassicHttpResponse backendResponse = chain.proceed(conditionalRequest, scope); diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java index bccb12aa8..e476c7643 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java @@ -26,7 +26,7 @@ */ package org.apache.hc.client5.http.impl.cache; -import java.util.Set; +import java.util.List; import org.apache.hc.client5.http.cache.HeaderConstants; import org.apache.hc.client5.http.cache.HttpCacheEntry; @@ -84,9 +84,9 @@ public T buildConditionalRequest(final ResponseCacheControl cacheControl, final * @param variants * @return the wrapped request */ - public T buildConditionalRequestFromVariants(final T request, final Set variants) { + public T buildConditionalRequestFromVariants(final T request, final List variants) { final T newRequest = messageCopier.create(request); - newRequest.setHeader(MessageSupport.format(HttpHeaders.IF_NONE_MATCH, variants)); + newRequest.setHeader(MessageSupport.headerOfTokens(HttpHeaders.IF_NONE_MATCH, variants)); return newRequest; } diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java index 1aadcac96..56360bf96 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java @@ -28,8 +28,7 @@ import java.time.Instant; import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.List; import org.apache.hc.client5.http.cache.HttpCacheEntry; import org.apache.hc.client5.http.utils.DateUtils; @@ -263,7 +262,7 @@ public void testBuildConditionalRequestFromVariants() throws Exception { final String etag2 = "\"456\""; final String etag3 = "\"789\""; - final Set variantEntries = new HashSet<>(Arrays.asList(etag1, etag2, etag3)); + final List variantEntries = Arrays.asList(etag1, etag2, etag3); final HttpRequest conditional = impl.buildConditionalRequestFromVariants(request, variantEntries); diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java index cdcf7bf39..0a83b6ab5 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSSLSocketFactory.java @@ -46,8 +46,6 @@ import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder; -import org.apache.hc.client5.http.ssl.TrustAllStrategy; -import org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy; import org.apache.hc.client5.testing.SSLTestContexts; import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.impl.bootstrap.HttpServer; @@ -287,21 +285,11 @@ public void testSSLTrustVerification() throws Exception { } @Test - public void testSSLTrustVerificationOverrideWithCustsom() throws Exception { + public void testSSLTrustVerificationOverrideWithCustom() throws Exception { final TrustStrategy trustStrategy = (chain, authType) -> chain.length == 1; testSSLTrustVerificationOverride(trustStrategy); } - @Test - public void testSSLTrustVerificationOverrideWithTrustSelfSignedStrategy() throws Exception { - testSSLTrustVerificationOverride(TrustSelfSignedStrategy.INSTANCE); - } - - @Test - public void testSSLTrustVerificationOverrideWithTrustAllStrategy() throws Exception { - testSSLTrustVerificationOverride(TrustAllStrategy.INSTANCE); - } - private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy) throws Exception, IOException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException { // @formatter:off diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestSupport.java index 50e879f38..5bec04cd3 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestSupport.java @@ -49,7 +49,7 @@ public static String extractPathPrefix(final HttpRequest request) { final URIBuilder uriBuilder = new URIBuilder(path); uriBuilder.setFragment(null); uriBuilder.clearParameters(); - uriBuilder.normalizeSyntax(); + uriBuilder.optimize(); final List pathSegments = uriBuilder.getPathSegments(); if (!pathSegments.isEmpty()) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java index 722e2eb8a..8bcdc3abe 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ContentCompressionExec.java @@ -28,6 +28,7 @@ package org.apache.hc.client5.http.impl.classic; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -88,15 +89,14 @@ public ContentCompressionExec( final boolean ignoreUnknown) { final boolean brotliSupported = BrotliDecompressingEntity.isAvailable(); - final String[] encoding; + final List encodings = new ArrayList<>(4); + encodings.add("gzip"); + encodings.add("x-gzip"); + encodings.add("deflate"); if (brotliSupported) { - encoding = new String[] {"gzip", "x-gzip", "deflate", "br"}; - } else { - encoding = new String[] {"gzip", "x-gzip", "deflate"}; + encodings.add("br"); } - this.acceptEncoding = MessageSupport.format(HttpHeaders.ACCEPT_ENCODING, - acceptEncoding != null ? acceptEncoding.toArray( - EMPTY_STRING_ARRAY) : encoding); + this.acceptEncoding = MessageSupport.headerOfTokens(HttpHeaders.ACCEPT_ENCODING, encodings); if (decoderRegistry != null) { this.decoderRegistry = decoderRegistry; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpResponseParserFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpResponseParserFactory.java index 108b293bd..290b64064 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpResponseParserFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpResponseParserFactory.java @@ -48,25 +48,53 @@ public class DefaultHttpResponseParserFactory implements HttpMessageParserFactor public static final DefaultHttpResponseParserFactory INSTANCE = new DefaultHttpResponseParserFactory(); + private final Http1Config h1Config; private final LineParser lineParser; private final HttpResponseFactory responseFactory; + /** + * @since 5.4 + */ public DefaultHttpResponseParserFactory( + final Http1Config h1Config, final LineParser lineParser, final HttpResponseFactory responseFactory) { super(); + this.h1Config = h1Config != null ? h1Config : Http1Config.DEFAULT; this.lineParser = lineParser != null ? lineParser : BasicLineParser.INSTANCE; this.responseFactory = responseFactory != null ? responseFactory : DefaultClassicHttpResponseFactory.INSTANCE; } + /** + * @since 5.4 + */ + public DefaultHttpResponseParserFactory(final Http1Config h1Config) { + this(h1Config, null, null); + } + + public DefaultHttpResponseParserFactory( + final LineParser lineParser, + final HttpResponseFactory responseFactory) { + this(null, lineParser, responseFactory); + } + public DefaultHttpResponseParserFactory(final HttpResponseFactory responseFactory) { - this(null, responseFactory); + this(null, null, responseFactory); } public DefaultHttpResponseParserFactory() { - this(null, null); + this(null, null, null); + } + + @Override + public HttpMessageParser create() { + return new LenientHttpResponseParser(this.lineParser, this.responseFactory, h1Config); } + /** + * @deprecated Use {@link #create()} + */ + @Deprecated @Override public HttpMessageParser create(final Http1Config h1Config) { return new LenientHttpResponseParser(this.lineParser, this.responseFactory, h1Config); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LenientHttpResponseParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LenientHttpResponseParser.java index 45da0c990..f2ba7c5f1 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LenientHttpResponseParser.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/LenientHttpResponseParser.java @@ -65,7 +65,7 @@ public LenientHttpResponseParser( final LineParser lineParser, final HttpResponseFactory responseFactory, final Http1Config h1Config) { - super(lineParser, responseFactory, h1Config); + super(h1Config, lineParser, responseFactory); } /** diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java index 503e34a93..0c520b253 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java @@ -81,9 +81,9 @@ private ManagedHttpClientConnectionFactory( this.h1Config = h1Config != null ? h1Config : Http1Config.DEFAULT; this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT; this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory : - DefaultHttpRequestWriterFactory.INSTANCE; + new DefaultHttpRequestWriterFactory(this.h1Config); this.responseParserFactory = responseParserFactory != null ? responseParserFactory : - DefaultHttpResponseParserFactory.INSTANCE; + new DefaultHttpResponseParserFactory(this.h1Config); this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy : DefaultContentLengthStrategy.INSTANCE; this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy : diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java index 3cd7c47a4..bb2074766 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConfiguration.java @@ -95,12 +95,18 @@ public class ClientConfiguration { public final static void main(final String[] args) throws Exception { + // Create HTTP/1.1 protocol configuration + final Http1Config h1Config = Http1Config.custom() + .setMaxHeaderCount(200) + .setMaxLineLength(2000) + .build(); + // Use custom message parser / writer to customize the way HTTP // messages are parsed from and written out to the data stream. final HttpMessageParserFactory responseParserFactory = new DefaultHttpResponseParserFactory() { @Override - public HttpMessageParser create(final Http1Config h1Config) { + public HttpMessageParser create() { final LineParser lineParser = new BasicLineParser() { @Override @@ -113,17 +119,12 @@ public Header parseHeader(final CharArrayBuffer buffer) { } }; - return new DefaultHttpResponseParser(lineParser, DefaultClassicHttpResponseFactory.INSTANCE, h1Config); + return new DefaultHttpResponseParser(h1Config, lineParser, DefaultClassicHttpResponseFactory.INSTANCE); } }; final HttpMessageWriterFactory requestWriterFactory = new DefaultHttpRequestWriterFactory(); - // Create HTTP/1.1 protocol configuration - final Http1Config h1Config = Http1Config.custom() - .setMaxHeaderCount(200) - .setMaxLineLength(2000) - .build(); // Create connection configuration final CharCodingConfig connectionConfig = CharCodingConfig.custom() .setMalformedInputAction(CodingErrorAction.IGNORE) diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicScheme.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicScheme.java index 22b1df6c8..b960045b7 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicScheme.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestBasicScheme.java @@ -118,7 +118,7 @@ public void testBasicAuthenticationDefaultCharset() throws Exception { public void testBasicAuthenticationDefaultCharsetUTF8() throws Exception { final HttpHost host = new HttpHost("somehost", 80); final UsernamePasswordCredentials creds = new UsernamePasswordCredentials("test", TEST_UTF8_PASSWORD.toCharArray()); - final BasicScheme authscheme = new BasicScheme(StandardCharsets.UTF_8); + final BasicScheme authscheme = new BasicScheme(); final HttpRequest request = new BasicHttpRequest("GET", "/"); authscheme.initPreemptive(creds); final String authResponse = authscheme.generateAuthResponse(host, request, null);