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 package org.apache.hc.client5.http.impl.async;
28
29 import java.io.Closeable;
30 import java.util.List;
31 import java.util.concurrent.ThreadFactory;
32
33 import org.apache.hc.client5.http.HttpRoute;
34 import org.apache.hc.client5.http.async.AsyncExecRuntime;
35 import org.apache.hc.client5.http.auth.AuthSchemeFactory;
36 import org.apache.hc.client5.http.auth.CredentialsProvider;
37 import org.apache.hc.client5.http.config.RequestConfig;
38 import org.apache.hc.client5.http.cookie.CookieSpecFactory;
39 import org.apache.hc.client5.http.cookie.CookieStore;
40 import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
41 import org.apache.hc.client5.http.protocol.HttpClientContext;
42 import org.apache.hc.client5.http.routing.HttpRoutePlanner;
43 import org.apache.hc.core5.annotation.Contract;
44 import org.apache.hc.core5.annotation.Internal;
45 import org.apache.hc.core5.annotation.ThreadingBehavior;
46 import org.apache.hc.core5.http.HttpException;
47 import org.apache.hc.core5.http.HttpHost;
48 import org.apache.hc.core5.http.HttpVersion;
49 import org.apache.hc.core5.http.ProtocolVersion;
50 import org.apache.hc.core5.http.config.Lookup;
51 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
52 import org.apache.hc.core5.http.nio.HandlerFactory;
53 import org.apache.hc.core5.http2.HttpVersionPolicy;
54 import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
57
58
59
60
61
62
63
64
65
66
67
68
69 @Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
70 @Internal
71 public final class InternalHttpAsyncClient extends InternalAbstractHttpAsyncClient {
72
73 private static final Logger LOG = LoggerFactory.getLogger(InternalHttpAsyncClient.class);
74 private final AsyncClientConnectionManager manager;
75 private final HttpRoutePlanner routePlanner;
76 private final HttpVersionPolicy versionPolicy;
77
78 InternalHttpAsyncClient(
79 final DefaultConnectingIOReactor ioReactor,
80 final AsyncExecChainElement execChain,
81 final AsyncPushConsumerRegistry pushConsumerRegistry,
82 final ThreadFactory threadFactory,
83 final AsyncClientConnectionManager manager,
84 final HttpRoutePlanner routePlanner,
85 final HttpVersionPolicy versionPolicy,
86 final Lookup<CookieSpecFactory> cookieSpecRegistry,
87 final Lookup<AuthSchemeFactory> authSchemeRegistry,
88 final CookieStore cookieStore,
89 final CredentialsProvider credentialsProvider,
90 final RequestConfig defaultConfig,
91 final List<Closeable> closeables) {
92 super(ioReactor, pushConsumerRegistry, threadFactory, execChain,
93 cookieSpecRegistry, authSchemeRegistry, cookieStore, credentialsProvider, defaultConfig, closeables);
94 this.manager = manager;
95 this.routePlanner = routePlanner;
96 this.versionPolicy = versionPolicy;
97 }
98
99 @Override
100 AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) {
101 return new InternalHttpAsyncExecRuntime(LOG, manager, getConnectionInitiator(), pushHandlerFactory, versionPolicy);
102 }
103
104 @Override
105 HttpRoute determineRoute(final HttpHost httpHost, final HttpClientContext clientContext) throws HttpException {
106 final HttpRoute route = routePlanner.determineRoute(httpHost, clientContext);
107 final ProtocolVersion protocolVersion = clientContext.getProtocolVersion();
108 if (route.isTunnelled() && protocolVersion.greaterEquals(HttpVersion.HTTP_2_0)) {
109 throw new HttpException("HTTP/2 tunneling not supported");
110 }
111 return route;
112 }
113
114 }