Package dev.relism.flash
Class RequestParser
java.lang.Object
dev.relism.flash.RequestParser
One instance per connection. The buffer is allocated once and reused across
keep-alive requests. Grows on demand (doubling, up to
maxHeaderBufferSize).
Zero-allocation design
- No
Stringallocations during parsing: paths, headers and protocol are exposed asByteViewslices into the shared buffer. headerMapis reset in-place per request — single allocation for the lifetime of the connection.- Pipelining / keep-alive leftover bytes are tracked via
bufBaseandbufLen— no copy between requests on the common path.
State invariant
bufBase and bufLen always reflect unconsumed bytes that belong
to the next request. They are snapshotted at the top of parse(java.io.InputStream)
and reset to 0/0 before any work begins, so an exception thrown mid-parse
leaves the fields clean rather than pointing at stale data from a previous request.-
Constructor Summary
ConstructorsConstructorDescriptionRequestParser(int maxHeaderBufferSize) RequestParser(int maxHeaderBufferSize, InetSocketAddress remoteAddress) -
Method Summary
-
Constructor Details
-
RequestParser
public RequestParser() -
RequestParser
public RequestParser(int maxHeaderBufferSize) -
RequestParser
-
-
Method Details
-
parse
Parses the next HTTP request fromin.Exception safety:
bufBaseandbufLenare reset to0before any parsing work begins. If an exception is thrown, the connection will be closed by the caller, so stale leftover state is never a problem — but the reset ensures correctness in test scenarios where the same parser instance is reused after an error.- Returns:
- the parsed
Request, ornullon clean EOF. - Throws:
IOException- on malformed headers or I/O failure.
-