Author: remy.maucherat(a)jboss.com
Date: 2012-11-14 09:08:45 -0500 (Wed, 14 Nov 2012)
New Revision: 2122
Modified:
branches/7.2.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java
Log:
- Probable fix for JBWEB-253 (a bit hard to test though since it depends on read size, and
I can get a telnet to go high enough).
- The NIO2 connector used the APR connector algorithm for the read, but the read size is
only constrained to the byte buffer size,
which may not fit in the array.
- Adjust the byte buffer size, the only relevant size being used on reading is always the
header array size (saves a tiny bit of memory).
Modified:
branches/7.2.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java
===================================================================
---
branches/7.2.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java 2012-11-13
12:55:22 UTC (rev 2121)
+++
branches/7.2.x/src/main/java/org/apache/coyote/http11/AbstractInternalInputBuffer.java 2012-11-14
14:08:45 UTC (rev 2122)
@@ -139,12 +139,7 @@
lastActiveFilter = -1;
parsingHeader = true;
swallowInput = true;
-
- if (headerBufferSize < (8 * 1024)) {
- bbuf = ByteBuffer.allocateDirect(6 * 1500);
- } else {
- bbuf = ByteBuffer.allocateDirect((headerBufferSize / 1500 + 1) * 1500);
- }
+ bbuf = ByteBuffer.allocateDirect(headerBufferSize);
}
/**
Modified:
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java
===================================================================
---
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2012-11-13
12:55:22 UTC (rev 2121)
+++
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2012-11-14
14:08:45 UTC (rev 2122)
@@ -57,11 +57,7 @@
headers = request.getMimeHeaders();
buf = new byte[headerBufferSize];
- if (headerBufferSize < (8 * 1024)) {
- bbuf = ByteBuffer.allocateDirect(6 * 1500);
- } else {
- bbuf = ByteBuffer.allocateDirect((headerBufferSize / 1500 + 1) * 1500);
- }
+ bbuf = ByteBuffer.allocateDirect(headerBufferSize);
inputStreamInputBuffer = new SocketInputBuffer();
Modified:
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java
===================================================================
---
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java 2012-11-13
12:55:22 UTC (rev 2121)
+++
branches/7.2.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java 2012-11-14
14:08:45 UTC (rev 2122)
@@ -401,6 +401,14 @@
nRead = blockingRead(bbuf, readTimeout, unit);
if (nRead > 0) {
bbuf.flip();
+ if (nRead > (buf.length - end)) {
+ // An alternative is to bbuf.setLimit(buf.length - end) before the read,
+ // which may be less efficient
+ buf = new byte[buf.length];
+ end = 0;
+ pos = end;
+ lastValid = pos;
+ }
bbuf.get(buf, pos, nRead);
lastValid = pos + nRead;
} else if (nRead == NioChannel.OP_STATUS_CLOSED) {
@@ -421,18 +429,9 @@
if (parsingHeader) {
if (lastValid == buf.length) {
- throw new IllegalArgumentException(MESSAGES.requestHeaderTooLarge());
+ throw MESSAGES.requestHeaderTooLarge();
}
} else {
- if (buf.length - end < 4500) {
- // In this case, the request header was really large, so we
- // allocate a
- // brand new one; the old one will get GCed when subsequent
- // requests
- // clear all references
- buf = new byte[buf.length];
- end = 0;
- }
pos = end;
lastValid = pos;
}