Class RequestParser

java.lang.Object
dev.relism.flash.RequestParser

public class RequestParser extends Object
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 String allocations during parsing: paths, headers and protocol are exposed as ByteView slices into the shared buffer.
  • headerMap is reset in-place per request — single allocation for the lifetime of the connection.
  • Pipelining / keep-alive leftover bytes are tracked via bufBase and bufLen — 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 Details

    • RequestParser

      public RequestParser()
    • RequestParser

      public RequestParser(int maxHeaderBufferSize)
    • RequestParser

      public RequestParser(int maxHeaderBufferSize, InetSocketAddress remoteAddress)
  • Method Details

    • parse

      public Request parse(InputStream in) throws IOException
      Parses the next HTTP request from in.

      Exception safety: bufBase and bufLen are reset to 0 before 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, or null on clean EOF.
      Throws:
      IOException - on malformed headers or I/O failure.