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.http.impl.nio;
29
30 import org.apache.hc.core5.annotation.Contract;
31 import org.apache.hc.core5.annotation.ThreadingBehavior;
32 import org.apache.hc.core5.http.HttpHost;
33 import org.apache.hc.core5.http.URIScheme;
34 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
35 import org.apache.hc.core5.reactor.EndpointParameters;
36 import org.apache.hc.core5.reactor.IOEventHandler;
37 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
38 import org.apache.hc.core5.reactor.ProtocolIOSession;
39 import org.apache.hc.core5.util.Args;
40 import org.apache.hc.core5.util.Timeout;
41
42
43
44
45
46
47 @Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
48 public class ClientHttp1IOEventHandlerFactory implements IOEventHandlerFactory {
49
50 private final ClientHttp1StreamDuplexerFactory streamDuplexerFactory;
51 private final TlsStrategy tlsStrategy;
52 private final Timeout handshakeTimeout;
53
54 public ClientHttp1IOEventHandlerFactory(
55 final ClientHttp1StreamDuplexerFactory streamDuplexerFactory,
56 final TlsStrategy tlsStrategy,
57 final Timeout handshakeTimeout) {
58 this.streamDuplexerFactory = Args.notNull(streamDuplexerFactory, "Stream duplexer factory");
59 this.tlsStrategy = tlsStrategy;
60 this.handshakeTimeout = handshakeTimeout;
61 }
62
63 @Override
64 public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
65 if (attachment instanceof EndpointParameters) {
66 final EndpointParameters../../../org/apache/hc/core5/reactor/EndpointParameters.html#EndpointParameters">EndpointParameters params = (EndpointParameters) attachment;
67 if (tlsStrategy != null && URIScheme.HTTPS.same(params.getScheme())) {
68 final HttpHost/http/HttpHost.html#HttpHost">HttpHost host = new HttpHost(params.getScheme(), params.getHostName(), params.getPort());
69 tlsStrategy.upgrade(
70 ioSession,
71 host,
72 ioSession.getLocalAddress(),
73 ioSession.getRemoteAddress(),
74 params.getAttachment(),
75 handshakeTimeout);
76 }
77 }
78 return new ClientHttp1IOEventHandler(streamDuplexerFactory.create(ioSession));
79 }
80
81 }