Fields Summary |
---|
protected static final String | ENCODING_NAME |
protected static final org.apache.tomcat.util.buf.ByteChunk | ENCODING |
protected org.apache.coyote.InputBuffer | bufferNext buffer in the pipeline. |
protected int | remainingNumber of bytes remaining in the current chunk. |
protected int | posPosition in the buffer. |
protected int | lastValidLast valid byte in the buffer. |
protected byte[] | bufRead bytes buffer. |
protected org.apache.tomcat.util.buf.ByteChunk | readChunkByte chunk used to read bytes. |
protected boolean | endChunkFlag set to true when the end chunk has been read. |
protected boolean | needCRLFParseFlag set to true if the next call to doRead() must parse a CRLF pair
before doing anything else. |
Methods Summary |
---|
public int | available()Amount of bytes still available in a buffer.
return (lastValid - pos);
|
public int | doRead(org.apache.tomcat.util.buf.ByteChunk chunk, org.apache.coyote.Request req)Read bytes.
// ------------------------------------------------------------- Properties
// ---------------------------------------------------- InputBuffer Methods
if (endChunk)
return -1;
if(needCRLFParse) {
needCRLFParse = false;
parseCRLF();
}
if (remaining <= 0) {
if (!parseChunkHeader()) {
throw new IOException("Invalid chunk header");
}
if (endChunk) {
parseEndChunk();
return -1;
}
}
int result = 0;
if (pos >= lastValid) {
readBytes();
}
if (remaining > (lastValid - pos)) {
result = lastValid - pos;
remaining = remaining - result;
chunk.setBytes(buf, pos, result);
pos = lastValid;
} else {
result = remaining;
chunk.setBytes(buf, pos, remaining);
pos = pos + remaining;
remaining = 0;
needCRLFParse = true;
}
return result;
|
public long | end()End the current request.
// Consume extra bytes : parse the stream until the end chunk is found
while (doRead(readChunk, null) >= 0) {
}
// Return the number of extra bytes which were consumed
return (lastValid - pos);
|
public org.apache.tomcat.util.buf.ByteChunk | getEncodingName()Return the name of the associated encoding; Here, the value is
"identity".
return ENCODING;
|
protected boolean | parseCRLF()Parse CRLF at end of chunk.
boolean eol = false;
while (!eol) {
if (pos >= lastValid) {
if (readBytes() <= 0)
throw new IOException("Invalid CRLF");
}
if (buf[pos] == Constants.CR) {
} else if (buf[pos] == Constants.LF) {
eol = true;
} else {
throw new IOException("Invalid CRLF");
}
pos++;
}
return true;
|
protected boolean | parseChunkHeader()Parse the header of a chunk.
A chunk header can look like
A10CRLF
F23;chunk-extension to be ignoredCRLF
The letters before CRLF but after the trailer mark, must be valid hex digits,
we should not parse F23IAMGONNAMESSTHISUP34CRLF as a valid header
according to spec
int result = 0;
boolean eol = false;
boolean readDigit = false;
boolean trailer = false;
while (!eol) {
if (pos >= lastValid) {
if (readBytes() <= 0)
return false;
}
if (buf[pos] == Constants.CR) {
} else if (buf[pos] == Constants.LF) {
eol = true;
} else if (buf[pos] == Constants.SEMI_COLON) {
trailer = true;
} else if (!trailer) {
//don't read data after the trailer
if (HexUtils.DEC[buf[pos]] != -1) {
readDigit = true;
result *= 16;
result += HexUtils.DEC[buf[pos]];
} else {
//we shouldn't allow invalid, non hex characters
//in the chunked header
return false;
}
}
pos++;
}
if (!readDigit)
return false;
if (result == 0)
endChunk = true;
remaining = result;
if (remaining < 0)
return false;
return true;
|
protected boolean | parseEndChunk()Parse end chunk data.
FIXME: Handle trailers
return parseCRLF(); // FIXME
|
protected int | readBytes()Read bytes from the previous buffer.
int nRead = buffer.doRead(readChunk, null);
pos = readChunk.getStart();
lastValid = pos + nRead;
buf = readChunk.getBytes();
return nRead;
|
public void | recycle()Make the filter ready to process the next request.
remaining = 0;
pos = 0;
lastValid = 0;
endChunk = false;
|
public void | setBuffer(org.apache.coyote.InputBuffer buffer)Set the next buffer in the filter pipeline.
this.buffer = buffer;
|
public void | setRequest(org.apache.coyote.Request request)Read the content length from the request.
|