org.apache.coyote.http11.Constants Java Examples

The following examples show how to use org.apache.coyote.http11.Constants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChunkedInputFilter.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Parse CRLF at end of chunk.
 *
 * @param   tolerant    Should tolerant parsing (LF and CRLF) be used? This
 *                      is recommended (RFC2616, section 19.3) for message
 *                      headers.
 * @throws IOException An error occurred parsing CRLF
 */
protected void parseCRLF(boolean tolerant) throws IOException {

    boolean eol = false;
    boolean crfound = false;

    while (!eol) {
        if (readChunk == null || readChunk.position() >= readChunk.limit()) {
            if (readBytes() <= 0) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfNoData"));
            }
        }

        byte chr = readChunk.get(readChunk.position());
        if (chr == Constants.CR) {
            if (crfound) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfCRCR"));
            }
            crfound = true;
        } else if (chr == Constants.LF) {
            if (!tolerant && !crfound) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfNoCR"));
            }
            eol = true;
        } else {
            throwIOException(sm.getString("chunkedInputFilter.invalidCrlf"));
        }

        readChunk.position(readChunk.position() + 1);
    }
}
 
Example #2
Source File: ChunkedInputFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Parse CRLF at end of chunk.
 *
 * @param   tolerant    Should tolerant parsing (LF and CRLF) be used? This
 *                      is recommended (RFC2616, section 19.3) for message
 *                      headers.
 */
protected void parseCRLF(boolean tolerant) throws IOException {

    boolean eol = false;
    boolean crfound = false;

    while (!eol) {
        if (pos >= lastValid) {
            if (readBytes() <= 0) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfNoData"));
            }
        }

        if (buf[pos] == Constants.CR) {
            if (crfound) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfCRCR"));
            }
            crfound = true;
        } else if (buf[pos] == Constants.LF) {
            if (!tolerant && !crfound) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfNoCR"));
            }
            eol = true;
        } else {
            throwIOException(sm.getString("chunkedInputFilter.invalidCrlf"));
        }

        pos++;
    }
}
 
Example #3
Source File: ChunkedInputFilter.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Parse CRLF at end of chunk.
 *
 * @param   tolerant    Should tolerant parsing (LF and CRLF) be used? This
 *                      is recommended (RFC2616, section 19.3) for message
 *                      headers.
 */
protected void parseCRLF(boolean tolerant) throws IOException {

    boolean eol = false;
    boolean crfound = false;

    while (!eol) {
        if (pos >= lastValid) {
            if (readBytes() <= 0) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfNoData"));
            }
        }

        if (buf[pos] == Constants.CR) {
            if (crfound) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfCRCR"));
            }
            crfound = true;
        } else if (buf[pos] == Constants.LF) {
            if (!tolerant && !crfound) {
                throwIOException(sm.getString("chunkedInputFilter.invalidCrlfNoCR"));
            }
            eol = true;
        } else {
            throwIOException(sm.getString("chunkedInputFilter.invalidCrlf"));
        }

        pos++;
    }
}
 
Example #4
Source File: ChunkedInputFilter.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Parse the header of a chunk.
 * A chunk header can look like one of the following:<br>
 * A10CRLF<br>
 * F23;chunk-extension to be ignoredCRLF
 *
 * <p>
 * The letters before CRLF or ';' (whatever comes first) must be valid hex
 * digits. We should not parse F23IAMGONNAMESSTHISUP34CRLF as a valid
 * header according to the spec.
 * @return <code>true</code> if the chunk header has been
 *  successfully parsed
 * @throws IOException Read error
 */
protected boolean parseChunkHeader() throws IOException {

    int result = 0;
    boolean eol = false;
    int readDigit = 0;
    boolean extension = false;

    while (!eol) {

        if (readChunk == null || readChunk.position() >= readChunk.limit()) {
            if (readBytes() <= 0)
                return false;
        }

        byte chr = readChunk.get(readChunk.position());
        if (chr == Constants.CR || chr == Constants.LF) {
            parseCRLF(false);
            eol = true;
        } else if (chr == Constants.SEMI_COLON && !extension) {
            // First semi-colon marks the start of the extension. Further
            // semi-colons may appear to separate multiple chunk-extensions.
            // These need to be processed as part of parsing the extensions.
            extension = true;
            extensionSize++;
        } else if (!extension) {
            //don't read data after the trailer
            int charValue = HexUtils.getDec(chr);
            if (charValue != -1 && readDigit < 8) {
                readDigit++;
                result = (result << 4) | charValue;
            } else {
                //we shouldn't allow invalid, non hex characters
                //in the chunked header
                return false;
            }
        } else {
            // Extension 'parsing'
            // Note that the chunk-extension is neither parsed nor
            // validated. Currently it is simply ignored.
            extensionSize++;
            if (maxExtensionSize > -1 && extensionSize > maxExtensionSize) {
                throwIOException(sm.getString("chunkedInputFilter.maxExtension"));
            }
        }

        // Parsing the CRLF increments pos
        if (!eol) {
            readChunk.position(readChunk.position() + 1);
        }
    }

    if (readDigit == 0 || result < 0) {
        return false;
    }

    if (result == 0) {
        endChunk = true;
    }

    remaining = result;
    return true;
}
 
Example #5
Source File: ChunkedInputFilter.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the header of a chunk.
 * A chunk header can look like one of the following:<br />
 * A10CRLF<br />
 * F23;chunk-extension to be ignoredCRLF
 *
 * <p>
 * The letters before CRLF or ';' (whatever comes first) must be valid hex
 * digits. We should not parse F23IAMGONNAMESSTHISUP34CRLF as a valid
 * header according to the spec.
 */
protected boolean parseChunkHeader() throws IOException {

    int result = 0;
    boolean eol = false;
    int readDigit = 0;
    boolean extension = false;

    while (!eol) {

        if (pos >= lastValid) {
            if (readBytes() <= 0)
                return false;
        }

        if (buf[pos] == Constants.CR || buf[pos] == Constants.LF) {
            parseCRLF(false);
            eol = true;
        } else if (buf[pos] == Constants.SEMI_COLON && !extension) {
            // First semi-colon marks the start of the extension. Further
            // semi-colons may appear to separate multiple chunk-extensions.
            // These need to be processed as part of parsing the extensions.
            extension = true;
            extensionSize++;
        } else if (!extension) {
            //don't read data after the trailer
            int charValue = HexUtils.getDec(buf[pos]);
            if (charValue != -1 && readDigit < 8) {
                readDigit++;
                result = (result << 4) | charValue;
            } else {
                //we shouldn't allow invalid, non hex characters
                //in the chunked header
                return false;
            }
        } else {
            // Extension 'parsing'
            // Note that the chunk-extension is neither parsed nor
            // validated. Currently it is simply ignored.
            extensionSize++;
            if (maxExtensionSize > -1 && extensionSize > maxExtensionSize) {
                throwIOException(sm.getString("chunkedInputFilter.maxExtension"));
            }
        }

        // Parsing the CRLF increments pos
        if (!eol) {
            pos++;
        }
    }

    if (readDigit == 0 || result < 0) {
        return false;
    }

    if (result == 0) {
        endChunk = true;
    }

    remaining = result;
    return true;
}
 
Example #6
Source File: ChunkedInputFilter.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the header of a chunk.
 * A chunk header can look like one of the following:<br />
 * A10CRLF<br />
 * F23;chunk-extension to be ignoredCRLF
 *
 * <p>
 * The letters before CRLF or ';' (whatever comes first) must be valid hex
 * digits. We should not parse F23IAMGONNAMESSTHISUP34CRLF as a valid
 * header according to the spec.
 */
protected boolean parseChunkHeader() throws IOException {

    int result = 0;
    boolean eol = false;
    int readDigit = 0;
    boolean extension = false;

    while (!eol) {

        if (pos >= lastValid) {
            if (readBytes() <= 0)
                return false;
        }

        if (buf[pos] == Constants.CR || buf[pos] == Constants.LF) {
            parseCRLF(false);
            eol = true;
        } else if (buf[pos] == Constants.SEMI_COLON && !extension) {
            // First semi-colon marks the start of the extension. Further
            // semi-colons may appear to separate multiple chunk-extensions.
            // These need to be processed as part of parsing the extensions.
            extension = true;
            extensionSize++;
        } else if (!extension) {
            //don't read data after the trailer
            int charValue = HexUtils.getDec(buf[pos]);
            if (charValue != -1 && readDigit < 8) {
                readDigit++;
                result = (result << 4) | charValue;
            } else {
                //we shouldn't allow invalid, non hex characters
                //in the chunked header
                return false;
            }
        } else {
            // Extension 'parsing'
            // Note that the chunk-extension is neither parsed nor
            // validated. Currently it is simply ignored.
            extensionSize++;
            if (maxExtensionSize > -1 && extensionSize > maxExtensionSize) {
                throwIOException(sm.getString("chunkedInputFilter.maxExtension"));
            }
        }

        // Parsing the CRLF increments pos
        if (!eol) {
            pos++;
        }
    }

    if (readDigit == 0 || result < 0) {
        return false;
    }

    if (result == 0) {
        endChunk = true;
    }

    remaining = result;
    return true;
}