7186954: Improve connection performance

Reviewed-by: chegar, skoivu
This commit is contained in:
Kurchi Subhra Hazra 2012-10-22 11:49:37 -07:00
parent c8ebc97b44
commit 64bb35a5c6
2 changed files with 20 additions and 3 deletions

View File

@ -41,8 +41,12 @@ class ChunkedInputStream extends LeftOverInputStream {
private boolean needToReadHeader = true;
static char CR = '\r';
static char LF = '\n';
final static char CR = '\r';
final static char LF = '\n';
/*
* Maximum chunk header size of 2KB + 2 bytes for CRLF
*/
private final static int MAX_CHUNK_HEADER_SIZE = 2050;
private int numeric (char[] arr, int nchars) throws IOException {
assert arr.length >= nchars;
@ -73,10 +77,14 @@ class ChunkedInputStream extends LeftOverInputStream {
char[] len_arr = new char [16];
int len_size = 0;
boolean end_of_len = false;
int read = 0;
while ((c=in.read())!= -1) {
char ch = (char) c;
if (len_size == len_arr.length -1) {
read++;
if ((len_size == len_arr.length -1) ||
(read > MAX_CHUNK_HEADER_SIZE))
{
throw new IOException ("invalid chunk header");
}
if (gotCR) {

View File

@ -125,6 +125,11 @@ class ChunkedInputStream extends InputStream implements Hurryable {
*/
private boolean closed;
/*
* Maximum chunk header size of 2KB + 2 bytes for CRLF
*/
private final static int MAX_CHUNK_HEADER_SIZE = 2050;
/**
* State to indicate that next field should be :-
* chunk-size [ chunk-extension ] CRLF
@ -290,6 +295,10 @@ class ChunkedInputStream extends InputStream implements Hurryable {
break;
}
pos++;
if ((pos - rawPos) >= MAX_CHUNK_HEADER_SIZE) {
error = true;
throw new IOException("Chunk header too long");
}
}
if (pos >= rawCount) {
return;