You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thrownewIllegalArgumentException("The maximum bytes to drain must be greater than or equal to 1024 and less than or equal to 268,435,456 (256 Megabytes)");
newRequestHeadersTooLargeException(maxSize, "The maximum size of the request header has been exceeded. The maximum size is [" + maxSize + "] bytes."));
140
-
141
131
// Not this line of code will block
142
132
// - When a client is using Keep-Alive - we will loop and block here while we wait for the client to send us bytes.
143
133
byte[] requestBuffer = buffers.requestBuffer();
144
-
HTTPTools.parseRequestPreamble(inputStream, request, requestBuffer, () -> state = State.Read);
134
+
HTTPTools.parseRequestPreamble(inputStream, configuration.getMaxRequestHeaderSize(), request, requestBuffer, () -> state = State.Read);
// Note that I am only tracing this. This is sort of expected - in that it is possible that the request handler will catch this exception and handle it. If the request handler
255
-
// does not handle this exception, it is totally fine to handle it here.
239
+
// Note that I am only tracing this, because this exception is mostly expected. Use closeSocketOnError so we can attempt to write a response.
256
240
logger.trace("[{}] Closing socket with status [{}]. An unhandled [{}] exception was taken. Reason [{}].", Thread.currentThread().threadId(), e.getStatus(), e.getClass().getSimpleName(), e.getMessage());
@@ -161,14 +170,32 @@ public int read(byte[] b, int off, int len) throws IOException {
161
170
}
162
171
163
172
// TODO : Daniel : Review : If we push back n bytes, don't we need to return read - n? This was previously read which ignored bytes pushed back.
173
+
// TODO : Daniel : Write a test to prove this, send a content-length of 100, buffer size 80 (as an example), ensure this returns 80, and then
174
+
// the next call returns 20?
175
+
176
+
177
+
bytesRead += reportBytesRead;
178
+
179
+
// This won't cause us to fail as fast as we could, but it keeps the code a bit simpler.
180
+
// - This means we will have read past the maximum by n where n is > 0 && < len. This seems like an acceptable over-read, in practice the buffers will be
181
+
if (maximumContentLength != -1) {
182
+
if (bytesRead > maximumContentLength) {
183
+
StringdetailedMessage = "The maximum request size has been exceeded.The maximum request size is [" + maximumContentLength + "] bytes.";
logger.trace("Client indicated it was NOT sending an entity-body in the request");
186
213
}
214
+
215
+
// If we have a maximumContentLength, and this is a fixed content length request, before we read any bytes, fail early.
216
+
// For good measure do this last so if anyone downstream wants to read from the InputStream they could in theory because
217
+
// we will have set up the InputStream.
218
+
if (contentLength != null && maximumContentLength != -1) {
219
+
if (contentLength > maximumContentLength) {
220
+
StringdetailedMessage = "The maximum request size has been exceeded. The reported Content-Length is [" + contentLength + "] and the maximum request size is [" + maximumContentLength + "] bytes.";
0 commit comments