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