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