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.protocol.HttpClientContext;
41 import org.apache.hc.client5.http.routing.HttpRoutePlanner;
42 import org.apache.hc.core5.annotation.Contract;
43 import org.apache.hc.core5.annotation.Internal;
44 import org.apache.hc.core5.annotation.ThreadingBehavior;
45 import org.apache.hc.core5.http.HttpException;
46 import org.apache.hc.core5.http.HttpHost;
47 import org.apache.hc.core5.http.config.Lookup;
48 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
49 import org.apache.hc.core5.http.nio.HandlerFactory;
50 import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54
55
56
57
58
59
60
61
62
63
64 @Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
65 @Internal
66 public final class InternalH2AsyncClient extends InternalAbstractHttpAsyncClient {
67
68 private static final Logger LOG = LoggerFactory.getLogger(InternalH2AsyncClient.class);
69 private final HttpRoutePlanner routePlanner;
70 private final InternalH2ConnPool connPool;
71
72 InternalH2AsyncClient(
73 final DefaultConnectingIOReactor ioReactor,
74 final AsyncExecChainElement execChain,
75 final AsyncPushConsumerRegistry pushConsumerRegistry,
76 final ThreadFactory threadFactory,
77 final InternalH2ConnPool connPool,
78 final HttpRoutePlanner routePlanner,
79 final Lookup<CookieSpecFactory> cookieSpecRegistry,
80 final Lookup<AuthSchemeFactory> authSchemeRegistry,
81 final CookieStore cookieStore,
82 final CredentialsProvider credentialsProvider,
83 final RequestConfig defaultConfig,
84 final List<Closeable> closeables) {
85 super(ioReactor, pushConsumerRegistry, threadFactory, execChain,
86 cookieSpecRegistry, authSchemeRegistry, cookieStore, credentialsProvider, defaultConfig, closeables);
87 this.connPool = connPool;
88 this.routePlanner = routePlanner;
89 }
90
91 @Override
92 AsyncExecRuntime createAsyncExecRuntime(final HandlerFactory<AsyncPushConsumer> pushHandlerFactory) {
93 return new InternalH2AsyncExecRuntime(LOG, connPool, pushHandlerFactory);
94 }
95
96 @Override
97 HttpRoute determineRoute(final HttpHost httpHost, final HttpClientContext clientContext) throws HttpException {
98 final HttpRoute route = routePlanner.determineRoute(httpHost, clientContext);
99 if (route.isTunnelled()) {
100 throw new HttpException("HTTP/2 tunneling not supported");
101 }
102 return route;
103 }
104
105 }