Skip to content

Commit 12a2445

Browse files
authored
Merge pull request #1955 from fl4via/UNDERTOW-2611_2.4.x
[UNDERTOW-2611] Ensure max-request-size of a Multipart servlet can ov…
2 parents 2ab6e54 + 8334977 commit 12a2445

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

core/src/main/java/io/undertow/server/protocol/http/HttpTransferEncoding.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
package io.undertow.server.protocol.http;
2020

21-
import java.io.IOException;
22-
2321
import io.undertow.UndertowLogger;
24-
import io.undertow.UndertowMessages;
2522
import io.undertow.UndertowOptions;
2623
import io.undertow.conduits.ChunkedStreamSinkConduit;
2724
import io.undertow.conduits.ChunkedStreamSourceConduit;
@@ -64,7 +61,7 @@ class HttpTransferEncoding {
6461
private HttpTransferEncoding() {
6562
}
6663

67-
public static void setupRequest(final HttpServerExchange exchange) throws IOException {
64+
public static void setupRequest(final HttpServerExchange exchange) {
6865
final HeaderMap requestHeaders = exchange.getRequestHeaders();
6966
final String connectionHeader = requestHeaders.getFirst(Headers.CONNECTION);
7067
final String transferEncodingHeader = requestHeaders.getLast(Headers.TRANSFER_ENCODING);
@@ -106,7 +103,7 @@ public static void setupRequest(final HttpServerExchange exchange) throws IOExce
106103

107104
}
108105

109-
private static boolean handleRequestEncoding(final HttpServerExchange exchange, String transferEncodingHeader, String contentLengthHeader, HttpServerConnection connection, PipeliningBufferingStreamSinkConduit pipeliningBuffer, boolean persistentConnection) throws IOException {
106+
private static boolean handleRequestEncoding(final HttpServerExchange exchange, String transferEncodingHeader, String contentLengthHeader, HttpServerConnection connection, PipeliningBufferingStreamSinkConduit pipeliningBuffer, boolean persistentConnection) {
110107

111108
HttpString transferEncoding = Headers.IDENTITY;
112109
if (transferEncodingHeader != null) {
@@ -123,15 +120,9 @@ private static boolean handleRequestEncoding(final HttpServerExchange exchange,
123120
// no content - immediately start the next request, returning an empty stream for this one
124121
Connectors.terminateRequest(exchange);
125122
} else {
126-
if (exchange.getMaxEntitySize() > 0 && exchange.getMaxEntitySize() < contentLength && exchange.isResponseChannelAvailable()) {
127-
persistentConnection = false;
128-
Connectors.terminateRequest(exchange);
129-
throw UndertowMessages.MESSAGES.requestEntityWasTooLarge(exchange.getMaxEntitySize());
130-
} else {
131-
// fixed-length content - add a wrapper for a fixed-length stream
132-
ConduitStreamSourceChannel sourceChannel = ((HttpServerConnection) exchange.getConnection()).getChannel().getSourceChannel();
133-
sourceChannel.setConduit(fixedLengthStreamSourceConduitWrapper(contentLength, sourceChannel.getConduit(), exchange));
134-
}
123+
// fixed-length content - add a wrapper for a fixed-length stream
124+
ConduitStreamSourceChannel sourceChannel = ((HttpServerConnection) exchange.getConnection()).getChannel().getSourceChannel();
125+
sourceChannel.setConduit(fixedLengthStreamSourceConduitWrapper(contentLength, sourceChannel.getConduit(), exchange));
135126
}
136127
} else if (transferEncodingHeader != null) {
137128
//identity transfer encoding

core/src/test/java/io/undertow/server/MaxRequestSizeTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void testMaxRequestEntitySize() throws IOException {
121121
post = new HttpPost(DefaultServer.getDefaultServerURL() + "/notamatchingpath");
122122
post.setEntity(new StringEntity(A_MESSAGE));
123123
result = client.execute(post);
124-
Assert.assertEquals(StatusCodes.BAD_REQUEST, result.getStatusLine().getStatusCode());
124+
Assert.assertEquals(StatusCodes.INTERNAL_SERVER_ERROR, result.getStatusLine().getStatusCode());
125125
HttpClientUtils.readResponse(result);
126126

127127
maxSize = OptionMap.create(UndertowOptions.MAX_HEADER_SIZE, 1000);

0 commit comments

Comments
 (0)