@@ -41,13 +41,17 @@ public static HttpServerOptions.Builder builder() {
41
41
private final int maxInitialLineLength ;
42
42
private final int maxHeaderSize ;
43
43
private final int maxChunkSize ;
44
+ private final int initialBufferSize ;
45
+ private final boolean validateHeaders ;
44
46
45
47
private HttpServerOptions (HttpServerOptions .Builder builder ) {
46
48
super (builder );
47
49
this .minCompressionResponseSize = builder .minCompressionResponseSize ;
48
50
this .maxInitialLineLength = builder .maxInitialLineLength ;
49
51
this .maxHeaderSize = builder .maxHeaderSize ;
50
52
this .maxChunkSize = builder .maxChunkSize ;
53
+ this .validateHeaders = builder .validateHeaders ;
54
+ this .initialBufferSize = builder .initialBufferSize ;
51
55
}
52
56
53
57
/**
@@ -90,6 +94,25 @@ public int httpCodecMaxChunkSize() {
90
94
return maxChunkSize ;
91
95
}
92
96
97
+ /**
98
+ * Returns the HTTP validate headers flag.
99
+ *
100
+ * @return true if the HTTP codec validates headers, false otherwise
101
+ * @see io.netty.handler.codec.http.HttpServerCodec
102
+ */
103
+ public boolean httpCodecValidateHeaders () {
104
+ return validateHeaders ;
105
+ }
106
+ /**
107
+ * Returns the configured HTTP codec initial buffer size.
108
+ *
109
+ * @return the configured HTTP codec initial buffer size
110
+ * @see io.netty.handler.codec.http.HttpServerCodec
111
+ */
112
+ public int httpCodecInitialBufferSize () {
113
+ return initialBufferSize ;
114
+ }
115
+
93
116
@ Override
94
117
public HttpServerOptions duplicate () {
95
118
return builder ().from (this ).build ();
@@ -123,10 +146,19 @@ public String toString() {
123
146
}
124
147
125
148
public static final class Builder extends ServerOptions .Builder <Builder > {
149
+
150
+ public static final int DEFAULT_MAX_INITIAL_LINE_LENGTH = 4096 ;
151
+ public static final int DEFAULT_MAX_HEADER_SIZE = 8192 ;
152
+ public static final int DEFAULT_MAX_CHUNK_SIZE = 8192 ;
153
+ public static final boolean DEFAULT_VALIDATE_HEADERS = true ;
154
+ public static final int DEFAULT_INITIAL_BUFFER_SIZE = 128 ;
155
+
126
156
private int minCompressionResponseSize = -1 ;
127
- private int maxInitialLineLength = 4096 ;
128
- private int maxHeaderSize = 8192 ;
129
- private int maxChunkSize = 8192 ;
157
+ private int maxInitialLineLength = DEFAULT_MAX_INITIAL_LINE_LENGTH ;
158
+ private int maxHeaderSize = DEFAULT_MAX_HEADER_SIZE ;
159
+ private int maxChunkSize = DEFAULT_MAX_CHUNK_SIZE ;
160
+ private boolean validateHeaders = DEFAULT_VALIDATE_HEADERS ;
161
+ private int initialBufferSize = DEFAULT_INITIAL_BUFFER_SIZE ;
130
162
131
163
private Builder (){
132
164
super (new ServerBootstrap ());
@@ -162,28 +194,75 @@ public final Builder compression(int minResponseSize) {
162
194
}
163
195
164
196
/**
165
- * Configure the {@link io.netty.handler.codec.http.HttpServerCodec HTTP codec}
166
- * maximum initial HTTP line length, header size and chunk size.
167
- * <p>
168
- * Negative or zero values are not valid, but will be interpreted as "don't change
169
- * the current configuration for that field": on first call the Netty defaults of
170
- * {@code (4096,8192,8192)} will be used.
197
+ * Configure the maximum length that can be decoded for the HTTP request's initial
198
+ * line. Defaults to {@code #DEFAULT_MAX_INITIAL_LINE_LENGTH}.
171
199
*
172
- * @param maxInitialLineLength the HTTP initial line maximum length. Use 0 to ignore/keep default.
173
- * @param maxHeaderSize the HTTP header maximum size. Use 0 to ignore/keep default.
174
- * @param maxChunkSize the HTTP chunk maximum size. Use 0 to ignore/keep default.
175
- * @return {@code this}
200
+ * @param value the value for the maximum initial line length (strictly positive)
201
+ * @return this option builder for further configuration
176
202
*/
177
- public final Builder httpCodecOptions (int maxInitialLineLength , int maxHeaderSize , int maxChunkSize ) {
178
- if (maxInitialLineLength > 0 ) {
179
- this .maxInitialLineLength = maxInitialLineLength ;
203
+ public final Builder maxInitialLineLength (int value ) {
204
+ if (value <= 0 ) {
205
+ throw new IllegalArgumentException (
206
+ "maxInitialLineLength must be strictly positive" );
180
207
}
181
- if (maxHeaderSize > 0 ) {
182
- this .maxHeaderSize = maxHeaderSize ;
208
+ this .maxInitialLineLength = value ;
209
+ return get ();
210
+ }
211
+
212
+ /**
213
+ * Configure the maximum header size that can be decoded for the HTTP request.
214
+ * Defaults to {@link #DEFAULT_MAX_HEADER_SIZE}.
215
+ *
216
+ * @param value the value for the maximum header size (strictly positive)
217
+ * @return this option builder for further configuration
218
+ */
219
+ public final Builder maxHeaderSize (int value ) {
220
+ if (value <= 0 ) {
221
+ throw new IllegalArgumentException ("maxHeaderSize must be strictly positive" );
183
222
}
184
- if (maxChunkSize > 0 ) {
185
- this .maxChunkSize = maxChunkSize ;
223
+ this .maxHeaderSize = value ;
224
+ return get ();
225
+ }
226
+
227
+ /**
228
+ * Configure the maximum chunk size that can be decoded for the HTTP request.
229
+ * Defaults to {@link #DEFAULT_MAX_CHUNK_SIZE}.
230
+ *
231
+ * @param value the value for the maximum chunk size (strictly positive)
232
+ * @return this option builder for further configuration
233
+ */
234
+ public final Builder maxChunkSize (int value ) {
235
+ if (value <= 0 ) {
236
+ throw new IllegalArgumentException ("maxChunkSize must be strictly positive" );
237
+ }
238
+ this .maxChunkSize = value ;
239
+ return get ();
240
+ }
241
+
242
+ /**
243
+ * Configure whether or not to validate headers when decoding requests. Defaults to
244
+ * #DEFAULT_VALIDATE_HEADERS.
245
+ *
246
+ * @param validate true to validate headers, false otherwise
247
+ * @return this option builder for further configuration
248
+ */
249
+ public final Builder validateHeaders (boolean validate ) {
250
+ this .validateHeaders = validate ;
251
+ return get ();
252
+ }
253
+
254
+ /**
255
+ * Configure the initial buffer size for HTTP request decoding. Defaults to
256
+ * {@link #DEFAULT_INITIAL_BUFFER_SIZE}.
257
+ *
258
+ * @param value the initial buffer size to use (strictly positive)
259
+ * @return
260
+ */
261
+ public final Builder initialBufferSize (int value ) {
262
+ if (value <= 0 ) {
263
+ throw new IllegalArgumentException ("initialBufferSize must be strictly positive" );
186
264
}
265
+ this .initialBufferSize = value ;
187
266
return get ();
188
267
}
189
268
@@ -199,6 +278,8 @@ public final Builder from(HttpServerOptions options) {
199
278
this .maxInitialLineLength = options .maxInitialLineLength ;
200
279
this .maxHeaderSize = options .maxHeaderSize ;
201
280
this .maxChunkSize = options .maxChunkSize ;
281
+ this .validateHeaders = options .validateHeaders ;
282
+ this .initialBufferSize = options .initialBufferSize ;
202
283
return get ();
203
284
}
204
285
0 commit comments