Skip to content

Commit 20044ab

Browse files
authored
Merge pull request #1824 from fl4via/backport-features_2.4.x_2
[UNDERTOW-2483 / 2473..2476 / 2495 / 2462 / 2481 / 2485 ] Port changes in UndertowOptions to 2.4.x
2 parents badf1ff + 15b96a9 commit 20044ab

File tree

14 files changed

+61
-24
lines changed

14 files changed

+61
-24
lines changed

core/src/main/java/io/undertow/Undertow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public synchronized void start() {
177177
listenerInfo.add(new ListenerInfo("ajp", server.getLocalAddress(), openListener, null, server));
178178
} else {
179179
OptionMap undertowOptions = OptionMap.builder().set(UndertowOptions.BUFFER_PIPELINED_DATA, true).addAll(serverOptions).getMap();
180-
boolean http2 = serverOptions.get(UndertowOptions.ENABLE_HTTP2, false);
180+
boolean http2 = serverOptions.get(UndertowOptions.ENABLE_HTTP2, UndertowOptions.DEFAULT_ENABLE_HTTP2);
181181
if (listener.type == ListenerType.HTTP) {
182182
HttpOpenListener openListener = new HttpOpenListener(buffers, undertowOptions);
183183
HttpHandler handler = rootHandler;

core/src/main/java/io/undertow/UndertowOptions.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,18 @@ public class UndertowOptions {
112112
*/
113113
public static final Option<Integer> MAX_COOKIES = Option.simple(UndertowOptions.class, "MAX_COOKIES", Integer.class);
114114

115+
/**
116+
* Default value of {@link #ALLOW_ENCODED_SLASH} option.
117+
*/
118+
public static final Boolean DEFAULT_ALLOW_ENCODED_SLASH = Boolean.FALSE;
119+
115120
/**
116121
* If a request comes in with encoded / characters (i.e. %2F), will these be decoded.
117122
* <p>
118123
* This can cause security problems if a front end proxy does not perform the same decoding, and as a result
119124
* this is disabled by default.
120125
* <p>
121-
* Defaults to false
126+
* Defaults to {@link #DEFAULT_ALLOW_ENCODED_SLASH}
122127
* <p>
123128
* See <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-0450">CVE-2007-0450</a>
124129
* @deprecated - this option was interpreted improperly.
@@ -232,17 +237,30 @@ public class UndertowOptions {
232237
@Deprecated
233238
public static final Option<Boolean> ENABLE_SPDY = Option.simple(UndertowOptions.class, "ENABLE_SPDY", Boolean.class);
234239

240+
/**
241+
* Default value of {@link #ENABLE_HTTP2} option.
242+
*/
243+
public static final boolean DEFAULT_ENABLE_HTTP2 = false;
244+
235245
/**
236246
* If we should attempt to use HTTP2 for HTTPS connections.
247+
* <p>
248+
* Defaults to {@link #DEFAULT_ENABLE_HTTP2}
237249
*/
238250
public static final Option<Boolean> ENABLE_HTTP2 = Option.simple(UndertowOptions.class, "ENABLE_HTTP2", Boolean.class);
239251

252+
/**
253+
* Default value of {@link #ENABLE_STATISTICS} option.
254+
*/
255+
public static final boolean DEFAULT_ENABLE_STATISTICS = false;
256+
240257
/**
241258
* If connector level statistics should be enabled. This has a slight performance impact, but allows statistics such
242259
* as bytes sent/recevied to be monitored.
243260
*
244261
* If this is passed to the client then client statistics will be enabled.
245-
*
262+
* <p>
263+
* Defaults to {@link #DEFAULT_ENABLE_STATISTICS}
246264
*/
247265
public static final Option<Boolean> ENABLE_STATISTICS = Option.simple(UndertowOptions.class, "ENABLE_STATISTICS", Boolean.class);
248266

@@ -251,9 +269,13 @@ public class UndertowOptions {
251269
* If connector level statistics should be enabled. This has a slight performance impact, but allows statistics such
252270
* as bytes sent/recevied to be monitored.
253271
*/
254-
@Deprecated
272+
@Deprecated(forRemoval = true)
255273
public static final Option<Boolean> ENABLE_CONNECTOR_STATISTICS = ENABLE_STATISTICS;
256274

275+
/**
276+
* Default value of {@link #ALLOW_UNKNOWN_PROTOCOLS} option.
277+
*/
278+
public static final Boolean DEFAULT_ALLOW_UNKNOWN_PROTOCOLS = false;
257279

258280
/**
259281
* If unknown protocols should be allowed. The known protocols are:
@@ -264,8 +286,8 @@ public class UndertowOptions {
264286
* HTTP/2.0
265287
*
266288
* If this is false then requests that specify any other protocol will be rejected with a 400
267-
*
268-
* Defaults to false
289+
* <p>
290+
* Defaults to {@link #DEFAULT_ALLOW_UNKNOWN_PROTOCOLS}
269291
*/
270292
public static final Option<Boolean> ALLOW_UNKNOWN_PROTOCOLS = Option.simple(UndertowOptions.class, "ALLOW_UNKNOWN_PROTOCOLS", Boolean.class);
271293

@@ -292,6 +314,10 @@ public class UndertowOptions {
292314
* <br>UNIT: Bytes.
293315
*/
294316
public static final Option<Integer> HTTP2_SETTINGS_INITIAL_WINDOW_SIZE = Option.simple(UndertowOptions.class, "HTTP2_SETTINGS_INITIAL_WINDOW_SIZE", Integer.class);
317+
/**
318+
* Default value of {@link #HTTP2_SETTINGS_INITIAL_WINDOW_SIZE}. <br>UNIT: Bytes.
319+
*/
320+
public static final int DEFAULT_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 65535;
295321
/**
296322
* Max frame size for HTTP2.
297323
* <br>UNIT: Bytes.
@@ -303,7 +329,7 @@ public class UndertowOptions {
303329
*
304330
* @see #MAX_HEADER_SIZE
305331
*/
306-
@Deprecated
332+
@Deprecated(forRemoval = true)
307333
public static final Option<Integer> HTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = Option.simple(UndertowOptions.class, "HTTP2_SETTINGS_MAX_HEADER_LIST_SIZE", Integer.class);
308334

309335
/**
@@ -332,7 +358,14 @@ public class UndertowOptions {
332358
public static final Option<Integer> MAX_CONCURRENT_REQUESTS_PER_CONNECTION = Option.simple(UndertowOptions.class, "MAX_CONCURRENT_REQUESTS_PER_CONNECTION", Integer.class);
333359

334360
/**
335-
* The maximum number of buffers that will be used before reads are paused in framed protocols. Defaults to 10
361+
* Default value of {@link #MAX_QUEUED_READ_BUFFERS} option.
362+
*/
363+
public static final int DEFAULT_MAX_QUEUED_READ_BUFFERS = 16;
364+
365+
/**
366+
* The maximum number of buffers that will be used before reads are paused in framed protocols.
367+
* <p>
368+
* Defaults to {@link #DEFAULT_MAX_QUEUED_READ_BUFFERS}
336369
*/
337370
public static final Option<Integer> MAX_QUEUED_READ_BUFFERS = Option.simple(UndertowOptions.class, "MAX_QUEUED_READ_BUFFERS", Integer.class);
338371

@@ -417,6 +450,9 @@ public class UndertowOptions {
417450
*
418451
* If not specified, the default value is null.
419452
*/
453+
454+
public static final Option<Integer> DEFAULT_QUEUED_FRAMES_LOW_WATER_MARK = null;
455+
420456
public static final Option<String> AJP_ALLOWED_REQUEST_ATTRIBUTES_PATTERN = Option.simple(UndertowOptions.class, "AJP_ALLOWED_REQUEST_ATTRIBUTES_PATTERN", String.class);
421457

422458
/**

core/src/main/java/io/undertow/client/ajp/AjpClientProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void handleConnected(StreamConnection connection, ClientCallback<ClientC
113113

114114
final ClientStatisticsImpl clientStatistics;
115115
//first we set up statistics, if required
116-
if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) {
116+
if (options.get(UndertowOptions.ENABLE_STATISTICS, UndertowOptions.DEFAULT_ENABLE_STATISTICS)) {
117117
clientStatistics = new ClientStatisticsImpl();
118118
connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() {
119119
@Override

core/src/main/java/io/undertow/client/http/HttpClientConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void handleEvent(StreamSourceConduit channel) {
150150
HttpClientConnection(final StreamConnection connection, final OptionMap options, final ByteBufferPool bufferPool) {
151151

152152
//first we set up statistics, if required
153-
if(options.get(UndertowOptions.ENABLE_STATISTICS, false)) {
153+
if(options.get(UndertowOptions.ENABLE_STATISTICS, UndertowOptions.DEFAULT_ENABLE_STATISTICS)) {
154154
clientStatistics = new ClientStatisticsImpl();
155155
connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() {
156156
@Override
@@ -358,7 +358,7 @@ public void sendRequest(final ClientRequest request, final ClientCallback<Client
358358
}
359359
final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this);
360360
boolean ssl = this.connection instanceof SslConnection;
361-
if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) {
361+
if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, UndertowOptions.DEFAULT_ENABLE_HTTP2) && !request.getRequestHeaders().contains(Headers.UPGRADE)) {
362362
//this is the first request, as we want to try a HTTP2 upgrade
363363
request.getRequestHeaders().put(new HttpString("HTTP2-Settings"), Http2ClearClientProvider.createSettingsFrame(options, bufferPool));
364364
request.getRequestHeaders().put(Headers.UPGRADE, Http2Channel.CLEARTEXT_UPGRADE_STRING);

core/src/main/java/io/undertow/client/http/HttpClientProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void handleEvent(SslConnection connection) {
162162

163163
private void handleConnected(final StreamConnection connection, final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, URI uri) {
164164

165-
boolean h2 = options.get(UndertowOptions.ENABLE_HTTP2, false);
165+
boolean h2 = options.get(UndertowOptions.ENABLE_HTTP2, UndertowOptions.DEFAULT_ENABLE_HTTP2);
166166
if(connection instanceof SslConnection && (h2)) {
167167
List<ALPNClientSelector.ALPNProtocol> protocolList = new ArrayList<>();
168168
if(h2) {

core/src/main/java/io/undertow/client/http2/Http2ClearClientProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void handleEvent(StreamConnection channel) {
207207

208208
final ClientStatisticsImpl clientStatistics;
209209
//first we set up statistics, if required
210-
if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) {
210+
if (options.get(UndertowOptions.ENABLE_STATISTICS, UndertowOptions.DEFAULT_ENABLE_STATISTICS)) {
211211
clientStatistics = new ClientStatisticsImpl();
212212
channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), new ByteActivityCallback() {
213213
@Override

core/src/main/java/io/undertow/client/http2/Http2ClientProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private static Http2ClientConnection createHttp2Channel(StreamConnection connect
155155

156156
final ClientStatisticsImpl clientStatistics;
157157
//first we set up statistics, if required
158-
if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) {
158+
if (options.get(UndertowOptions.ENABLE_STATISTICS, UndertowOptions.DEFAULT_ENABLE_STATISTICS)) {
159159
clientStatistics = new ClientStatisticsImpl();
160160
connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() {
161161
@Override

core/src/main/java/io/undertow/client/http2/Http2PriorKnowledgeClientProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void handleConnected(final StreamConnection connection, final ClientCall
113113

114114
final ClientStatisticsImpl clientStatistics;
115115
//first we set up statistics, if required
116-
if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) {
116+
if (options.get(UndertowOptions.ENABLE_STATISTICS, UndertowOptions.DEFAULT_ENABLE_STATISTICS)) {
117117
clientStatistics = new ClientStatisticsImpl();
118118
connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() {
119119
@Override

core/src/main/java/io/undertow/protocols/http2/Http2Channel.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ public class Http2Channel extends AbstractFramedChannel<Http2Channel, AbstractHt
145145

146146
static final int CONTINUATION_FLAG_END_HEADERS = 0x4;
147147

148-
public static final int DEFAULT_INITIAL_WINDOW_SIZE = 65535;
149-
150148
static final byte[] PREFACE_BYTES = {
151149
0x50, 0x52, 0x49, 0x20, 0x2a, 0x20, 0x48, 0x54,
152150
0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a,
@@ -230,7 +228,7 @@ public class Http2Channel extends AbstractFramedChannel<Http2Channel, AbstractHt
230228
/**
231229
* The initial window size for newly created channels, guarded by {@link #flowControlLock}
232230
*/
233-
private volatile int initialSendWindowSize = DEFAULT_INITIAL_WINDOW_SIZE;
231+
private volatile int initialSendWindowSize = UndertowOptions.DEFAULT_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
234232
/**
235233
* How much data we can send to the remote endpoint, at the connection level, guarded by {@link #flowControlLock}
236234
*/
@@ -257,7 +255,7 @@ public Http2Channel(StreamConnection connectedStreamChannel, String protocol, By
257255
streamIdCounter = clientSide ? (fromUpgrade ? 3 : 1) : 2;
258256

259257
pushEnabled = settings.get(UndertowOptions.HTTP2_SETTINGS_ENABLE_PUSH, true);
260-
this.initialReceiveWindowSize = settings.get(UndertowOptions.HTTP2_SETTINGS_INITIAL_WINDOW_SIZE, DEFAULT_INITIAL_WINDOW_SIZE);
258+
this.initialReceiveWindowSize = settings.get(UndertowOptions.HTTP2_SETTINGS_INITIAL_WINDOW_SIZE, UndertowOptions.DEFAULT_HTTP2_SETTINGS_INITIAL_WINDOW_SIZE);
261259
this.receiveWindowSize = initialReceiveWindowSize;
262260
this.receiveMaxConcurrentStreams = settings.get(UndertowOptions.HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, UndertowOptions.DEFAULT_HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS);
263261

core/src/main/java/io/undertow/server/protocol/framed/AbstractFramedChannel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void handleEvent(AbstractFramedChannel channel) {
205205
*/
206206
protected AbstractFramedChannel(final StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, FramePriority<C, R, S> framePriority, final PooledByteBuffer readData, OptionMap settings) {
207207
this.framePriority = framePriority;
208-
this.maxQueuedBuffers = settings.get(UndertowOptions.MAX_QUEUED_READ_BUFFERS, 16);
208+
this.maxQueuedBuffers = settings.get(UndertowOptions.MAX_QUEUED_READ_BUFFERS, UndertowOptions.DEFAULT_MAX_QUEUED_READ_BUFFERS);
209209
this.settings = settings;
210210
if (readData != null) {
211211
if(readData.getBuffer().hasRemaining()) {

0 commit comments

Comments
 (0)