* Do NOT perform any blocking operations in any of these methods. A typical example would be trying to send another
* request and calling get() on its future.
- * There's a chance you might end up in a dead lock.
+ * There's a chance you might end up in a deadlock.
* If you really need to perform a blocking operation, execute it in a different dedicated thread pool.
*
* @param
- * Might be called several times if the name was resolved to multiple addresses and we failed to connect to the first(s) one(s).
+ * Might be called several times if the name was resolved to multiple addresses, and we failed to connect to the first(s) one(s).
*
* @param remoteAddress the address we try to connect to
*/
diff --git a/client/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/client/src/main/java/org/asynchttpclient/AsyncHttpClient.java
index 9e86b9f84..01a3ecf73 100755
--- a/client/src/main/java/org/asynchttpclient/AsyncHttpClient.java
+++ b/client/src/main/java/org/asynchttpclient/AsyncHttpClient.java
@@ -66,7 +66,7 @@
* The {@link AsyncCompletionHandler#onCompleted(Response)} method will be invoked once the http response has been fully read.
* The {@link Response} object includes the http headers and the response body. Note that the entire response will be buffered in memory.
*
+ * If false (default), AHC will either leave AcceptEncoding header as is
+ * (if enableAutomaticDecompression is false) or will remove unsupported
+ * algorithms (if enableAutomaticDecompression is true)
+ */
public Builder setCompressionEnforced(boolean compressionEnforced) {
this.compressionEnforced = compressionEnforced;
return this;
}
+ /*
+ * If true (default), AHC will add a Netty HttpContentDecompressor, so compressed
+ * content will automatically get decompressed.
+ *
+ * If set to false, response will be delivered as is received. Decompression must
+ * be done by calling code.
+ */
+ public Builder setEnableAutomaticDecompression(boolean enable) {
+ enableAutomaticDecompression = enable;
+ return this;
+ }
+
public Builder setUserAgent(String userAgent) {
this.userAgent = userAgent;
return this;
@@ -1037,6 +1089,11 @@ public Builder setUseProxyProperties(boolean useProxyProperties) {
return this;
}
+ public Builder setStripAuthorizationOnRedirect(boolean value) {
+ stripAuthorizationOnRedirect = value;
+ return this;
+ }
+
// websocket
public Builder setAggregateWebSocketFrameFragments(boolean aggregateWebSocketFrameFragments) {
this.aggregateWebSocketFrameFragments = aggregateWebSocketFrameFragments;
@@ -1390,6 +1447,7 @@ public DefaultAsyncHttpClientConfig build() {
maxRedirects,
strict302Handling,
compressionEnforced,
+ enableAutomaticDecompression,
userAgent,
realm,
maxRequestRetry,
@@ -1401,6 +1459,7 @@ public DefaultAsyncHttpClientConfig build() {
validateResponseHeaders,
aggregateWebSocketFrameFragments,
enablewebSocketCompression,
+ stripAuthorizationOnRedirect,
connectTimeout,
requestTimeout,
readTimeout,
diff --git a/client/src/main/java/org/asynchttpclient/DefaultRequest.java b/client/src/main/java/org/asynchttpclient/DefaultRequest.java
index a885e67a9..09c615d2a 100644
--- a/client/src/main/java/org/asynchttpclient/DefaultRequest.java
+++ b/client/src/main/java/org/asynchttpclient/DefaultRequest.java
@@ -15,6 +15,7 @@
*/
package org.asynchttpclient;
+import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.cookie.Cookie;
import io.netty.resolver.NameResolver;
@@ -23,6 +24,7 @@
import org.asynchttpclient.request.body.generator.BodyGenerator;
import org.asynchttpclient.request.body.multipart.Part;
import org.asynchttpclient.uri.Uri;
+import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.InputStream;
@@ -39,58 +41,60 @@
public class DefaultRequest implements Request {
- public final ProxyServer proxyServer;
+ public final @Nullable ProxyServer proxyServer;
private final String method;
private final Uri uri;
- private final InetAddress address;
- private final InetAddress localAddress;
+ private final @Nullable InetAddress address;
+ private final @Nullable InetAddress localAddress;
private final HttpHeaders headers;
private final List
- * You can also have more control about the how the response is asynchronously processed by using an {@link AsyncHandler}
+ * You can also have more control about how the response is asynchronously processed by using an {@link AsyncHandler}
*
* AsyncHttpClient c = new AsyncHttpClient();
* Future<String> f = c.prepareGet(TARGET_URL).execute(new AsyncHandler<String>() {
@@ -149,7 +149,7 @@ public interface AsyncHttpClient extends Closeable {
* Prepare an HTTP client request.
*
* @param method HTTP request method type. MUST BE in upper case
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder prepare(String method, String url);
@@ -158,7 +158,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client GET request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder prepareGet(String url);
@@ -166,7 +166,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client CONNECT request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder prepareConnect(String url);
@@ -174,7 +174,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client OPTIONS request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder prepareOptions(String url);
@@ -182,7 +182,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client HEAD request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder prepareHead(String url);
@@ -190,7 +190,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client POST request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder preparePost(String url);
@@ -198,7 +198,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client PUT request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder preparePut(String url);
@@ -206,7 +206,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client DELETE request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder prepareDelete(String url);
@@ -214,7 +214,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client PATCH request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder preparePatch(String url);
@@ -222,7 +222,7 @@ public interface AsyncHttpClient extends Closeable {
/**
* Prepare an HTTP client TRACE request.
*
- * @param url A well formed URL.
+ * @param url A well-formed URL.
* @return {@link RequestBuilder}
*/
BoundRequestBuilder prepareTrace(String url);
diff --git a/client/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/client/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java
index ee2775cc6..216dc4ed6 100644
--- a/client/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java
+++ b/client/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java
@@ -34,6 +34,7 @@
import org.asynchttpclient.netty.channel.ConnectionSemaphoreFactory;
import org.asynchttpclient.proxy.ProxyServer;
import org.asynchttpclient.proxy.ProxyServerSelector;
+import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.time.Duration;
@@ -146,12 +147,20 @@ public interface AsyncHttpClientConfig {
*/
boolean isCompressionEnforced();
+ /**
+ * If automatic content decompression is enabled.
+ *
+ * @return true if content decompression is enabled
+ */
+ boolean isEnableAutomaticDecompression();
+
/**
* Return the {@link ThreadFactory} an {@link AsyncHttpClient} use for handling asynchronous response.
*
* @return the {@link ThreadFactory} an {@link AsyncHttpClient} use for handling asynchronous response. If no {@link ThreadFactory} has been explicitly
* provided, this method will return {@code null}
*/
+ @Nullable
ThreadFactory getThreadFactory();
/**
@@ -166,6 +175,7 @@ public interface AsyncHttpClientConfig {
*
* @return an instance of {@link SslContext} used for SSL connection.
*/
+ @Nullable
SslContext getSslContext();
/**
@@ -173,6 +183,7 @@ public interface AsyncHttpClientConfig {
*
* @return the current {@link Realm}
*/
+ @Nullable
Realm getRealm();
/**
@@ -223,7 +234,7 @@ public interface AsyncHttpClientConfig {
boolean isDisableUrlEncodingForBoundRequests();
/**
- * @return true if AHC is to use a LAX cookie encoder, eg accept illegal chars in cookie value
+ * @return true if AHC is to use a LAX cookie encoder, e.g. accept illegal chars in cookie value
*/
boolean isUseLaxCookieEncoder();
@@ -252,11 +263,13 @@ public interface AsyncHttpClientConfig {
/**
* @return the array of enabled protocols
*/
+ @Nullable
String[] getEnabledProtocols();
/**
* @return the array of enabled cipher suites
*/
+ @Nullable
String[] getEnabledCipherSuites();
/**
@@ -286,6 +299,7 @@ public interface AsyncHttpClientConfig {
int getHandshakeTimeout();
+ @Nullable
SslEngineFactory getSslEngineFactory();
int getChunkedFileChunkSize();
@@ -302,22 +316,28 @@ public interface AsyncHttpClientConfig {
Map
* There is no guaranteed ordering of execution of listeners, they may get
- * called in the order they were added and they may get called out of order,
+ * called in the order they were added, and they may get called out of order,
* but any listener added through this method is guaranteed to be called once
* the computation is complete.
*
diff --git a/client/src/main/java/org/asynchttpclient/Param.java b/client/src/main/java/org/asynchttpclient/Param.java
index 397d5b5fa..4f7a5530a 100644
--- a/client/src/main/java/org/asynchttpclient/Param.java
+++ b/client/src/main/java/org/asynchttpclient/Param.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2023 AsyncHttpClient Project. All rights reserved.
+ * Copyright (c) 2014-2024 AsyncHttpClient Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.asynchttpclient;
+import org.jetbrains.annotations.Nullable;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -27,14 +29,14 @@
public class Param {
private final String name;
- private final String value;
+ private final @Nullable String value;
- public Param(String name, String value) {
+ public Param(String name, @Nullable String value) {
this.name = name;
this.value = value;
}
- public static List map2ParamList(Map