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.http.impl;
29
30 import org.apache.http.HttpConnectionFactory;
31 import org.apache.http.HttpRequest;
32 import org.apache.http.HttpResponse;
33 import org.apache.http.annotation.ThreadingBehavior;
34 import org.apache.http.annotation.Contract;
35 import org.apache.http.config.ConnectionConfig;
36 import org.apache.http.entity.ContentLengthStrategy;
37 import org.apache.http.io.HttpMessageParserFactory;
38 import org.apache.http.io.HttpMessageWriterFactory;
39
40 import java.io.IOException;
41 import java.net.Socket;
42
43
44
45
46
47
48 @Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
49 public class DefaultBHttpServerConnectionFactory
50 implements HttpConnectionFactory<DefaultBHttpServerConnection> {
51
52 public static final DefaultBHttpServerConnectionFactoryml#DefaultBHttpServerConnectionFactory">DefaultBHttpServerConnectionFactory INSTANCE = new DefaultBHttpServerConnectionFactory();
53
54 private final ConnectionConfig cconfig;
55 private final ContentLengthStrategy incomingContentStrategy;
56 private final ContentLengthStrategy outgoingContentStrategy;
57 private final HttpMessageParserFactory<HttpRequest> requestParserFactory;
58 private final HttpMessageWriterFactory<HttpResponse> responseWriterFactory;
59
60 public DefaultBHttpServerConnectionFactory(
61 final ConnectionConfig cconfig,
62 final ContentLengthStrategy incomingContentStrategy,
63 final ContentLengthStrategy outgoingContentStrategy,
64 final HttpMessageParserFactory<HttpRequest> requestParserFactory,
65 final HttpMessageWriterFactory<HttpResponse> responseWriterFactory) {
66 super();
67 this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
68 this.incomingContentStrategy = incomingContentStrategy;
69 this.outgoingContentStrategy = outgoingContentStrategy;
70 this.requestParserFactory = requestParserFactory;
71 this.responseWriterFactory = responseWriterFactory;
72 }
73
74 public DefaultBHttpServerConnectionFactory(
75 final ConnectionConfig cconfig,
76 final HttpMessageParserFactory<HttpRequest> requestParserFactory,
77 final HttpMessageWriterFactory<HttpResponse> responseWriterFactory) {
78 this(cconfig, null, null, requestParserFactory, responseWriterFactory);
79 }
80
81 public DefaultBHttpServerConnectionFactory(final ConnectionConfig cconfig) {
82 this(cconfig, null, null, null, null);
83 }
84
85 public DefaultBHttpServerConnectionFactory() {
86 this(null, null, null, null, null);
87 }
88
89 @Override
90 public DefaultBHttpServerConnection createConnection(final Socket socket) throws IOException {
91 final DefaultBHttpServerConnectionn.html#DefaultBHttpServerConnection">DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(
92 this.cconfig.getBufferSize(),
93 this.cconfig.getFragmentSizeHint(),
94 ConnSupport.createDecoder(this.cconfig),
95 ConnSupport.createEncoder(this.cconfig),
96 this.cconfig.getMessageConstraints(),
97 this.incomingContentStrategy,
98 this.outgoingContentStrategy,
99 this.requestParserFactory,
100 this.responseWriterFactory);
101 conn.bind(socket);
102 return conn;
103 }
104
105 }