Skip to content

Commit 7eaf234

Browse files
committed
Follow-up to PR #1147
1 parent b2b86f6 commit 7eaf234

4 files changed

Lines changed: 12 additions & 17 deletions

File tree

‎java/org/apache/coyote/http11/Http11Processor.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ public SocketState service(SocketWrapperBase<?> socketWrapper) throws IOExceptio
309309
}
310310
setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe);
311311
break;
312+
} catch (RequestTargetTooLongException e) {
313+
response.setStatus(HttpServletResponse.SC_REQUEST_URI_TOO_LONG);
314+
setErrorState(ErrorState.CLOSE_CLEAN, e);
312315
} catch (Throwable t) {
313316
ExceptionUtils.handleThrowable(t);
314317
UserDataHelper.Mode logMode = userDataHelper.getNextMode();
@@ -325,8 +328,7 @@ public SocketState service(SocketWrapperBase<?> socketWrapper) throws IOExceptio
325328
log.debug(message, t);
326329
}
327330
}
328-
// 414 - URI Too Long (RFC 9112, section 3) or 400 - Bad Request
329-
response.setStatus(t instanceof RequestTargetTooLongException ? 414 : 400);
331+
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
330332
setErrorState(ErrorState.CLOSE_CLEAN, t);
331333
}
332334

‎java/org/apache/coyote/http11/RequestTargetTooLongException.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
/**
2222
* Exception used to mark the specific error condition of the request target exceeding the size of the buffer used to
2323
* read the request line.
24-
*
25-
* @since 12.0.x
2624
*/
2725
public class RequestTargetTooLongException extends IllegalArgumentException {
2826

‎test/org/apache/coyote/http11/TestHttp11InputBuffer.java‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,8 @@ public void testRequestTargetTooLong() {
803803
LongRequestClient client = new LongRequestClient("/test/" + "a".repeat(9000), "X-Test: a");
804804

805805
Exception e = client.doRequest();
806-
if (e == null) {
807-
Assert.assertTrue(client.getResponseLine(), client.isResponse414());
808-
}
809-
Assert.assertFalse(client.isResponseBodyOK());
806+
Assert.assertNull(e);
807+
Assert.assertTrue(client.getResponseLine(), client.isResponse414());
810808
}
811809

812810

@@ -815,10 +813,8 @@ public void testRequestTargetQueryTooLong() {
815813
LongRequestClient client = new LongRequestClient("/test?q=" + "a".repeat(9000), "X-Test: a");
816814

817815
Exception e = client.doRequest();
818-
if (e == null) {
819-
Assert.assertTrue(client.getResponseLine(), client.isResponse414());
820-
}
821-
Assert.assertFalse(client.isResponseBodyOK());
816+
Assert.assertNull(e);
817+
Assert.assertTrue(client.getResponseLine(), client.isResponse414());
822818
}
823819

824820

@@ -830,10 +826,8 @@ public void testRequestHeaderTooLarge() {
830826
LongRequestClient client = new LongRequestClient("/test", "X-Test: " + "a".repeat(9000));
831827

832828
Exception e = client.doRequest();
833-
if (e == null) {
834-
Assert.assertTrue(client.getResponseLine(), client.isResponse400());
835-
}
836-
Assert.assertFalse(client.isResponseBodyOK());
829+
Assert.assertNull(e);
830+
Assert.assertTrue(client.getResponseLine(), client.isResponse400());
837831
}
838832

839833

‎webapps/docs/changelog.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@
287287
<fix>
288288
Respond with a 414 (URI Too Long) status rather than a 400 (Bad Request)
289289
status when the request target is too long to fit in the buffer used to
290-
read the request line, as required by RFC 9112, section 3. (abernal)
290+
read the request line, as required by RFC 9112, section 3. Pull request
291+
<pr>1147</pr> provided by Arturo Bernal. (markt)
291292
</fix>
292293
</changelog>
293294
</subsection>

0 commit comments

Comments
 (0)