mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-16 15:07:27 +00:00
Removed references to deprecated functions
This commit is contained in:
parent
20bd815e74
commit
4dc82b40f6
@ -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() {
|
||||
|
@ -143,7 +143,7 @@ public static URI normalize(final URI requestUri) throws URISyntaxException {
|
||||
}
|
||||
}
|
||||
builder.setFragment(null);
|
||||
return builder.normalizeSyntax().build();
|
||||
return builder.optimize().build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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<String> variants) {
|
||||
public T buildConditionalRequestFromVariants(final T request, final List<String> 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;
|
||||
}
|
||||
|
||||
|
@ -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<String> variantEntries = new HashSet<>(Arrays.asList(etag1, etag2, etag3));
|
||||
final List<String> variantEntries = Arrays.asList(etag1, etag2, etag3);
|
||||
|
||||
final HttpRequest conditional = impl.buildConditionalRequestFromVariants(request, variantEntries);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<String> pathSegments = uriBuilder.getPathSegments();
|
||||
|
||||
if (!pathSegments.isEmpty()) {
|
||||
|
@ -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<String> 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;
|
||||
|
@ -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<ClassicHttpResponse> responseFactory;
|
||||
|
||||
/**
|
||||
* @since 5.4
|
||||
*/
|
||||
public DefaultHttpResponseParserFactory(
|
||||
final Http1Config h1Config,
|
||||
final LineParser lineParser,
|
||||
final HttpResponseFactory<ClassicHttpResponse> 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<ClassicHttpResponse> responseFactory) {
|
||||
this(null, lineParser, responseFactory);
|
||||
}
|
||||
|
||||
public DefaultHttpResponseParserFactory(final HttpResponseFactory<ClassicHttpResponse> responseFactory) {
|
||||
this(null, responseFactory);
|
||||
this(null, null, responseFactory);
|
||||
}
|
||||
|
||||
public DefaultHttpResponseParserFactory() {
|
||||
this(null, null);
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpMessageParser<ClassicHttpResponse> create() {
|
||||
return new LenientHttpResponseParser(this.lineParser, this.responseFactory, h1Config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #create()}
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public HttpMessageParser<ClassicHttpResponse> create(final Http1Config h1Config) {
|
||||
return new LenientHttpResponseParser(this.lineParser, this.responseFactory, h1Config);
|
||||
|
@ -65,7 +65,7 @@ public LenientHttpResponseParser(
|
||||
final LineParser lineParser,
|
||||
final HttpResponseFactory<ClassicHttpResponse> responseFactory,
|
||||
final Http1Config h1Config) {
|
||||
super(lineParser, responseFactory, h1Config);
|
||||
super(h1Config, lineParser, responseFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 :
|
||||
|
@ -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<ClassicHttpResponse> responseParserFactory = new DefaultHttpResponseParserFactory() {
|
||||
|
||||
@Override
|
||||
public HttpMessageParser<ClassicHttpResponse> create(final Http1Config h1Config) {
|
||||
public HttpMessageParser<ClassicHttpResponse> 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<ClassicHttpRequest> 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)
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user