-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathAsyncHttpClientConfig.java
387 lines (302 loc) · 11 KB
/
AsyncHttpClientConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
* Copyright (c) 2015-2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asynchttpclient;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.handler.ssl.SslContext;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.asynchttpclient.channel.ChannelPool;
import org.asynchttpclient.channel.KeepAliveStrategy;
import org.asynchttpclient.cookie.CookieStore;
import org.asynchttpclient.filter.IOExceptionFilter;
import org.asynchttpclient.filter.RequestFilter;
import org.asynchttpclient.filter.ResponseFilter;
import org.asynchttpclient.netty.EagerResponseBodyPart;
import org.asynchttpclient.netty.LazyResponseBodyPart;
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;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
import java.util.function.Consumer;
public interface AsyncHttpClientConfig {
/**
* @return the version of AHC
*/
String getAhcVersion();
/**
* Return the name of {@link AsyncHttpClient}, which is used for thread naming and debugging.
*
* @return the name.
*/
String getThreadPoolName();
/**
* Return the maximum number of connections an {@link AsyncHttpClient} can handle.
*
* @return the maximum number of connections an {@link AsyncHttpClient} can handle.
*/
int getMaxConnections();
/**
* Return the maximum number of connections per hosts an {@link AsyncHttpClient} can handle.
*
* @return the maximum number of connections per host an {@link AsyncHttpClient} can handle.
*/
int getMaxConnectionsPerHost();
/**
* Return the maximum duration in milliseconds an {@link AsyncHttpClient} can wait to acquire a free channel
*
* @return Return the maximum duration in milliseconds an {@link AsyncHttpClient} can wait to acquire a free channel
*/
int getAcquireFreeChannelTimeout();
/**
* Return the maximum time an {@link AsyncHttpClient} can wait when connecting to a remote host
*
* @return the maximum time an {@link AsyncHttpClient} can wait when connecting to a remote host
*/
Duration getConnectTimeout();
/**
* Return the maximum time an {@link AsyncHttpClient} can stay idle.
*
* @return the maximum time an {@link AsyncHttpClient} can stay idle.
*/
Duration getReadTimeout();
/**
* Return the maximum time an {@link AsyncHttpClient} will keep connection in pool.
*
* @return the maximum time an {@link AsyncHttpClient} will keep connection in pool.
*/
Duration getPooledConnectionIdleTimeout();
/**
* @return the period to clean the pool of dead and idle connections.
*/
Duration getConnectionPoolCleanerPeriod();
/**
* Return the maximum time an {@link AsyncHttpClient} waits until the response is completed.
*
* @return the maximum time an {@link AsyncHttpClient} waits until the response is completed.
*/
Duration getRequestTimeout();
/**
* Is HTTP redirect enabled
*
* @return true if enabled.
*/
boolean isFollowRedirect();
/**
* Get the maximum number of HTTP redirect
*
* @return the maximum number of HTTP redirect
*/
int getMaxRedirects();
/**
* Is the {@link ChannelPool} support enabled.
*
* @return true if keep-alive is enabled
*/
boolean isKeepAlive();
/**
* Return the USER_AGENT header value
*
* @return the USER_AGENT header value
*/
String getUserAgent();
/**
* Is HTTP compression enforced.
*
* @return true if compression is enforced
*/
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();
/**
* An instance of {@link ProxyServer} used by an {@link AsyncHttpClient}
*
* @return instance of {@link ProxyServer}
*/
ProxyServerSelector getProxyServerSelector();
/**
* Return an instance of {@link SslContext} used for SSL connection.
*
* @return an instance of {@link SslContext} used for SSL connection.
*/
@Nullable SslContext getSslContext();
/**
* Return the current {@link Realm}
*
* @return the current {@link Realm}
*/
@Nullable Realm getRealm();
/**
* Return the list of {@link RequestFilter}
*
* @return Unmodifiable list of {@link RequestFilter}
*/
List<RequestFilter> getRequestFilters();
/**
* Return the list of {@link ResponseFilter}
*
* @return Unmodifiable list of {@link ResponseFilter}
*/
List<ResponseFilter> getResponseFilters();
/**
* Return the list of {@link IOException}
*
* @return Unmodifiable list of {@link IOException}
*/
List<IOExceptionFilter> getIoExceptionFilters();
/**
* Return cookie store that is used to store and retrieve cookies
*
* @return {@link CookieStore} object
*/
CookieStore getCookieStore();
/**
* Return the delay in milliseconds to evict expired cookies from {@linkplain CookieStore}
*
* @return the delay in milliseconds to evict expired cookies from {@linkplain CookieStore}
*/
int expiredCookieEvictionDelay();
/**
* Return the number of time the library will retry when an {@link IOException} is throw by the remote server
*
* @return the number of time the library will retry when an {@link IOException} is throw by the remote server
*/
int getMaxRequestRetry();
/**
* @return the disableUrlEncodingForBoundRequests
*/
boolean isDisableUrlEncodingForBoundRequests();
/**
* @return true if AHC is to use a LAX cookie encoder, e.g. accept illegal chars in cookie value
*/
boolean isUseLaxCookieEncoder();
/**
* In the case of a POST/Redirect/Get scenario where the server uses a 302 for the redirect, should AHC respond to the redirect with a GET or whatever the original method was.
* Unless configured otherwise, for a 302, AHC, will use a GET for this case.
*
* @return {@code true} if strict 302 handling is to be used, otherwise {@code false}.
*/
boolean isStrict302Handling();
/**
* @return the maximum time an {@link AsyncHttpClient} will keep connection in the pool, or negative value to keep connection while possible.
*/
Duration getConnectionTtl();
boolean isUseOpenSsl();
boolean isUseInsecureTrustManager();
/**
* @return true to disable all HTTPS behaviors AT ONCE, such as hostname verification and SNI
*/
boolean isDisableHttpsEndpointIdentificationAlgorithm();
/**
* @return the array of enabled protocols
*/
@Nullable String[] getEnabledProtocols();
/**
* @return the array of enabled cipher suites
*/
@Nullable String[] getEnabledCipherSuites();
/**
* @return if insecure cipher suites must be filtered out (only used when not explicitly passing enabled cipher suites)
*/
boolean isFilterInsecureCipherSuites();
/**
* @return the size of the SSL session cache, 0 means using the default value
*/
int getSslSessionCacheSize();
/**
* @return the SSL session timeout in seconds, 0 means using the default value
*/
int getSslSessionTimeout();
int getHttpClientCodecMaxInitialLineLength();
int getHttpClientCodecMaxHeaderSize();
int getHttpClientCodecMaxChunkSize();
int getHttpClientCodecInitialBufferSize();
boolean getHttpClientCodecParseHttpAfterConnectRequest();
boolean getHttpClientCodecAllowDuplicateContentLengths();
boolean isDisableZeroCopy();
int getHandshakeTimeout();
@Nullable SslEngineFactory getSslEngineFactory();
int getChunkedFileChunkSize();
int getWebSocketMaxBufferSize();
int getWebSocketMaxFrameSize();
boolean isKeepEncodingHeader();
Duration getShutdownQuietPeriod();
Duration getShutdownTimeout();
Map<ChannelOption<Object>, Object> getChannelOptions();
@Nullable EventLoopGroup getEventLoopGroup();
boolean isUseNativeTransport();
boolean isUseOnlyEpollNativeTransport();
@Nullable Consumer<Channel> getHttpAdditionalChannelInitializer();
@Nullable Consumer<Channel> getWsAdditionalChannelInitializer();
ResponseBodyPartFactory getResponseBodyPartFactory();
@Nullable ChannelPool getChannelPool();
@Nullable ConnectionSemaphoreFactory getConnectionSemaphoreFactory();
@Nullable Timer getNettyTimer();
/**
* @return the duration between tick of {@link HashedWheelTimer}
*/
long getHashedWheelTimerTickDuration();
/**
* @return the size of the hashed wheel {@link HashedWheelTimer}
*/
int getHashedWheelTimerSize();
KeepAliveStrategy getKeepAliveStrategy();
boolean isValidateResponseHeaders();
boolean isAggregateWebSocketFrameFragments();
boolean isEnableWebSocketCompression();
boolean isTcpNoDelay();
boolean isSoReuseAddress();
boolean isSoKeepAlive();
int getSoLinger();
int getSoSndBuf();
int getSoRcvBuf();
@Nullable ByteBufAllocator getAllocator();
int getIoThreadsCount();
enum ResponseBodyPartFactory {
EAGER {
@Override
public HttpResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
return new EagerResponseBodyPart(buf, last);
}
},
LAZY {
@Override
public HttpResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) {
return new LazyResponseBodyPart(buf, last);
}
};
public abstract HttpResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last);
}
}