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 package org.apache.hc.core5.testing.nio;
29
30 import java.io.IOException;
31
32 import org.apache.hc.core5.function.Supplier;
33 import org.apache.hc.core5.http.URIScheme;
34 import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
35 import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
36 import org.apache.hc.core5.http.impl.routing.RequestRouter;
37 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
38 import org.apache.hc.core5.http2.HttpVersionPolicy;
39 import org.apache.hc.core5.reactor.IOReactorConfig;
40 import org.apache.hc.core5.testing.extension.SocksProxyResource;
41 import org.apache.hc.core5.testing.nio.extension.H2AsyncRequesterResource;
42 import org.apache.hc.core5.testing.nio.extension.H2AsyncServerResource;
43 import org.apache.hc.core5.util.Timeout;
44 import org.junit.jupiter.api.Order;
45 import org.junit.jupiter.api.extension.RegisterExtension;
46
47 public abstract class H2SocksProxyCoreTransportTest extends HttpCoreTransportTest {
48
49 private static final Timeout TIMEOUT = Timeout.ofMinutes(1);
50
51 @RegisterExtension
52 @Order(-Integer.MAX_VALUE)
53 private final SocksProxyResource proxyResource;
54 @RegisterExtension
55 private final H2AsyncServerResource serverResource;
56 @RegisterExtension
57 private final H2AsyncRequesterResource clientResource;
58
59 public H2SocksProxyCoreTransportTest(final URIScheme scheme) {
60 super(scheme);
61 this.proxyResource = new SocksProxyResource();
62 this.serverResource = new H2AsyncServerResource(bootstrap -> bootstrap
63 .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
64 .setIOReactorConfig(
65 IOReactorConfig.custom()
66 .setSoTimeout(TIMEOUT)
67 .build())
68 .setRequestRouter(RequestRouter.<Supplier<AsyncServerExchangeHandler>>builder()
69 .addRoute(RequestRouter.LOCAL_AUTHORITY, "*", () -> new EchoHandler(2048))
70 .resolveAuthority(RequestRouter.LOCAL_AUTHORITY_RESOLVER)
71 .build())
72 );
73 this.clientResource = new H2AsyncRequesterResource(bootstrap -> bootstrap
74 .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
75 .setIOReactorConfig(IOReactorConfig.custom()
76 .setSocksProxyAddress(proxyResource.proxy().getProxyAddress())
77 .setSoTimeout(TIMEOUT)
78 .build())
79 );
80 }
81
82 @Override
83 HttpAsyncServer serverStart() throws IOException {
84 return serverResource.start();
85 }
86
87 @Override
88 HttpAsyncRequester clientStart() {
89 return clientResource.start();
90 }
91
92 }