Package org.apache.hc.core5.http.impl.io
Class AbstractMessageParser<T extends HttpMessage>
java.lang.Object
org.apache.hc.core5.http.impl.io.AbstractMessageParser<T>
- All Implemented Interfaces:
HttpMessageParser<T>
- Direct Known Subclasses:
DefaultHttpRequestParser
,DefaultHttpResponseParser
public abstract class AbstractMessageParser<T extends HttpMessage>
extends Object
implements HttpMessageParser<T>
Abstract base class for HTTP message parsers that obtain input from
an instance of
SessionInputBuffer
.- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private final List
<CharArrayBuffer> private static final int
private final CharArrayBuffer
private final Http1Config
private final LineParser
private T
private int
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractMessageParser
(LineParser lineParser, Http1Config http1Config) Creates new instance of AbstractMessageParser. -
Method Summary
Modifier and TypeMethodDescriptionprotected IOException
Deprecated.do not use.protected abstract T
createMessage
(CharArrayBuffer buffer) Subclasses must override this method to generate an instance ofHttpMessage
based on the initial input from the session buffer.(package private) LineParser
parse
(SessionInputBuffer buffer, InputStream inputStream) Generates an instance ofMessageHeaders
from the given input stream..static Header[]
parseHeaders
(SessionInputBuffer inBuffer, InputStream inputStream, int maxHeaderCount, int maxLineLen, LineParser lineParser) Parses HTTP headers from the data receiver stream according to the generic format as specified by the HTTP/1.1 protocol specification.static Header[]
parseHeaders
(SessionInputBuffer inBuffer, InputStream inputStream, int maxHeaderCount, int maxLineLen, LineParser parser, List<CharArrayBuffer> headerLines) Parses HTTP headers from the data receiver stream according to the generic format as specified by the HTTP/1.1 protocol specification.
-
Field Details
-
HEAD_LINE
private static final int HEAD_LINE- See Also:
-
HEADERS
private static final int HEADERS- See Also:
-
http1Config
-
headerLines
-
headLine
-
lineParser
-
state
private int state -
message
-
-
Constructor Details
-
AbstractMessageParser
Creates new instance of AbstractMessageParser.- Parameters:
lineParser
- the line parser. Ifnull
LazyLineParser.INSTANCE
will be used.http1Config
- the message http1Config. Ifnull
Http1Config.DEFAULT
will be used.- Since:
- 4.3
-
-
Method Details
-
getLineParser
LineParser getLineParser() -
parseHeaders
public static Header[] parseHeaders(SessionInputBuffer inBuffer, InputStream inputStream, int maxHeaderCount, int maxLineLen, LineParser lineParser) throws HttpException, IOException Parses HTTP headers from the data receiver stream according to the generic format as specified by the HTTP/1.1 protocol specification.- Parameters:
inBuffer
- Session input bufferinputStream
- Input streammaxHeaderCount
- maximum number of headers allowed. If the number of headers received from the data stream exceeds maxCount value, an IOException will be thrown. Setting this parameter to a negative value or zero will disable the check.maxLineLen
- maximum number of characters for a header line, including the continuation lines. Setting this parameter to a negative value or zero will disable the check.lineParser
- the line parser. Ifnull
LazyLineParser.INSTANCE
will be used- Returns:
- array of HTTP headers
- Throws:
IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation
-
parseHeaders
public static Header[] parseHeaders(SessionInputBuffer inBuffer, InputStream inputStream, int maxHeaderCount, int maxLineLen, LineParser parser, List<CharArrayBuffer> headerLines) throws HttpException, IOException Parses HTTP headers from the data receiver stream according to the generic format as specified by the HTTP/1.1 protocol specification.- Parameters:
inBuffer
- Session input bufferinputStream
- Input streammaxHeaderCount
- maximum number of headers allowed. If the number of headers received from the data stream exceeds maxCount value, an IOException will be thrown. Setting this parameter to a negative value or zero will disable the check.maxLineLen
- maximum number of characters for a header line, including the continuation lines. Setting this parameter to a negative value or zero will disable the check.parser
- line parser to use.headerLines
- List of header lines. This list will be used to store intermediate results. This makes it possible to resume parsing of headers in case of aInterruptedIOException
.- Returns:
- array of HTTP headers
- Throws:
IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation- Since:
- 4.1
-
createMessage
Subclasses must override this method to generate an instance ofHttpMessage
based on the initial input from the session buffer.Usually this method is expected to read just the very first line or the very first valid from the data stream and based on the input generate an appropriate instance of
HttpMessage
.- Parameters:
buffer
- the session input buffer.- Returns:
- HTTP message based on the input from the session buffer.
- Throws:
IOException
- in case of an I/O error.HttpException
- in case of HTTP protocol violation.- Since:
- 5.0
-
createConnectionClosedException
Deprecated.do not use.Subclasses must override this method to generate an appropriate exception in case of unexpected connection termination by the peer endpoint.- Since:
- 5.0
-
parse
public T parse(SessionInputBuffer buffer, InputStream inputStream) throws IOException, HttpException Description copied from interface:HttpMessageParser
Generates an instance ofMessageHeaders
from the given input stream..- Specified by:
parse
in interfaceHttpMessageParser<T extends HttpMessage>
- Parameters:
buffer
- Session input bufferinputStream
- Input stream- Returns:
- HTTP message head or
null
if the input stream has been closed by the opposite endpoint. - Throws:
IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation
-