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.Internal;
32 import org.apache.hc.core5.annotation.ThreadingBehavior;
33 import org.apache.hc.core5.http.ConnectionReuseStrategy;
34 import org.apache.hc.core5.http.ContentLengthStrategy;
35 import org.apache.hc.core5.http.HttpRequest;
36 import org.apache.hc.core5.http.HttpResponse;
37 import org.apache.hc.core5.http.config.CharCodingConfig;
38 import org.apache.hc.core5.http.config.Http1Config;
39 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
40 import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
41 import org.apache.hc.core5.http.impl.Http1StreamListener;
42 import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
43 import org.apache.hc.core5.http.nio.NHttpMessageWriterFactory;
44 import org.apache.hc.core5.http.protocol.HttpProcessor;
45 import org.apache.hc.core5.reactor.ProtocolIOSession;
46 import org.apache.hc.core5.util.Args;
47
48
49
50
51
52
53 @Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
54 @Internal
55 public final class ClientHttp1StreamDuplexerFactory {
56
57 private final HttpProcessor httpProcessor;
58 private final Http1Config http1Config;
59 private final CharCodingConfig charCodingConfig;
60 private final ConnectionReuseStrategy connectionReuseStrategy;
61 private final NHttpMessageParserFactory<HttpResponse> responseParserFactory;
62 private final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory;
63 private final ContentLengthStrategy incomingContentStrategy;
64 private final ContentLengthStrategy outgoingContentStrategy;
65 private final Http1StreamListener streamListener;
66
67 public ClientHttp1StreamDuplexerFactory(
68 final HttpProcessor httpProcessor,
69 final Http1Config http1Config,
70 final CharCodingConfig charCodingConfig,
71 final ConnectionReuseStrategy connectionReuseStrategy,
72 final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
73 final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
74 final ContentLengthStrategy incomingContentStrategy,
75 final ContentLengthStrategy outgoingContentStrategy,
76 final Http1StreamListener streamListener) {
77 this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
78 this.http1Config = http1Config != null ? http1Config : Http1Config.DEFAULT;
79 this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
80 this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
81 DefaultConnectionReuseStrategy.INSTANCE;
82 this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
83 new DefaultHttpResponseParserFactory(http1Config);
84 this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory :
85 DefaultHttpRequestWriterFactory.INSTANCE;
86 this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
87 DefaultContentLengthStrategy.INSTANCE;
88 this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
89 DefaultContentLengthStrategy.INSTANCE;
90 this.streamListener = streamListener;
91 }
92
93 public ClientHttp1StreamDuplexerFactory(
94 final HttpProcessor httpProcessor,
95 final Http1Config http1Config,
96 final CharCodingConfig charCodingConfig,
97 final ConnectionReuseStrategy connectionReuseStrategy,
98 final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
99 final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
100 final Http1StreamListener streamListener) {
101 this(httpProcessor, http1Config, charCodingConfig, connectionReuseStrategy,
102 responseParserFactory, requestWriterFactory, null, null, streamListener);
103 }
104
105 public ClientHttp1StreamDuplexerFactory(
106 final HttpProcessor httpProcessor,
107 final Http1Config http1Config,
108 final CharCodingConfig charCodingConfig,
109 final Http1StreamListener streamListener) {
110 this(httpProcessor, http1Config, charCodingConfig, null, null, null, streamListener);
111 }
112
113 public ClientHttp1StreamDuplexerFactory(
114 final HttpProcessor httpProcessor,
115 final Http1Config http1Config,
116 final CharCodingConfig charCodingConfig) {
117 this(httpProcessor, http1Config, charCodingConfig, null);
118 }
119
120 public ClientHttp1StreamDuplexer create(final ProtocolIOSession ioSession) {
121 return new ClientHttp1StreamDuplexer(
122 ioSession,
123 httpProcessor,
124 http1Config,
125 charCodingConfig,
126 connectionReuseStrategy,
127 responseParserFactory.create(),
128 requestWriterFactory.create(),
129 incomingContentStrategy,
130 outgoingContentStrategy,
131 streamListener);
132 }
133
134 }