Class Http1HeaderMap

java.lang.Object
dev.relism.flash.models.Http1HeaderMap
All Implemented Interfaces:
HeaderView

public class Http1HeaderMap extends Object implements HeaderView
HeaderView backed directly by RequestParser's byte buffer — lazy, zero-copy: strings are allocated only when first(java.lang.String)/all(java.lang.String)/view(java.lang.String) is called, the raw bytes are never copied at parse time.

Package placement

Despite the Http1 prefix, this class lives in dev.relism.flash.models, not dev.relism.flash.http1, deliberately: RequestParser (which owns and resets one instance per connection) lives in the root dev.relism.flash package, and http1 already depends on root (via Http1Connection's use of RequestParser) — placing this class in http1 would require root to import back from http1, the exact reader does not "fix" the location back to what the plan's Files list originally suggested.

Lifetime contract — read carefully

One Http1HeaderMap instance lives on the connection (not per-request). On every keep-alive request reset(byte[], int, int) is called to slide the window over the new header section of the same reused buffer. This has two critical implications:
  1. Do not retain the Http1HeaderMap beyond the handler. After the handler returns, the next request reuses and overwrites the buffer. Any String values retrieved via first(java.lang.String)/all(java.lang.String) are safe (they are independent heap copies); the Http1HeaderMap object itself is not.
  2. view(java.lang.String) returns a zero-copy ByteView slice into the live buffer, drawn from a small SlicePool (see view(java.lang.String)'s own Javadoc for the exact reuse window). Storing this view and reading it after the handler returns (e.g. in an async callback, a CompletableFuture continuation, or a virtual-thread handoff) is a data race — the bytes may have been overwritten by the next request. Copy to a String or byte[] before leaving the synchronous handler scope.
reset(byte[], int, int) scans the header section exactly once and records, per header, its name/value byte offsets and a case-insensitive 32-bit hash of the name — into int[] arrays grown (never shrunk) to this connection's high-water mark. Every lookup method (first(java.lang.String), all(java.lang.String), view(java.lang.String), valueEqualsIgnoreCase(java.lang.String, java.lang.String)) then walks that small index instead of rescanning raw bytes: a hash compare (cheap) before ever falling back to a full case-insensitive name comparison.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface dev.relism.flash.models.HeaderView

    HeaderView.HeaderConsumer
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addParsed(int nameOffset, int nameLength, int valueOffset, int valueLength)
    Adds one already-validated header to the current zero-copy index.
    all()
    Returns all header values in declaration order.
    all(String name)
    Returns all values of header name in declaration order, or an empty list.
    void
    beginParsed(byte[] buffer, int sectionStart, int sectionEnd)
    Starts an index populated by the request parser while it validates the same header lines.
    boolean
    Whether any header named name is present.
    int
    Total number of header lines (not distinct names — a repeated header counts once per line).
    first(String name)
    Returns the first value of header name (case-insensitive), or null.
    void
    Visits every header in declaration order without allocating a per-header object — see each implementation's Javadoc for exactly which instances are reused and their validity window.
    void
    reset(byte[] buffer, int sectionStart, int sectionEnd)
     
    boolean
    Case-insensitive comparison of the first value of name against value.
    dev.relism.fpr.core.ByteView
    view(String name)
    Returns a zero-copy ByteView over the first value of name, or null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Http1HeaderMap

      public Http1HeaderMap()
  • Method Details

    • reset

      public void reset(byte[] buffer, int sectionStart, int sectionEnd)
    • beginParsed

      public void beginParsed(byte[] buffer, int sectionStart, int sectionEnd)
      Starts an index populated by the request parser while it validates the same header lines. This avoids rescanning a validated section solely to recover offsets already known there.
    • addParsed

      public void addParsed(int nameOffset, int nameLength, int valueOffset, int valueLength)
      Adds one already-validated header to the current zero-copy index.
    • forEach

      public void forEach(HeaderView.HeaderConsumer consumer)
      Description copied from interface: HeaderView
      Visits every header in declaration order without allocating a per-header object — see each implementation's Javadoc for exactly which instances are reused and their validity window.
      Specified by:
      forEach in interface HeaderView
    • first

      public String first(String name)
      Description copied from interface: HeaderView
      Returns the first value of header name (case-insensitive), or null.
      Specified by:
      first in interface HeaderView
    • all

      public List<String> all(String name)
      Description copied from interface: HeaderView
      Returns all values of header name in declaration order, or an empty list.
      Specified by:
      all in interface HeaderView
    • all

      public List<String> all()
      Description copied from interface: HeaderView
      Returns all header values in declaration order.
      Specified by:
      all in interface HeaderView
    • valueEqualsIgnoreCase

      public boolean valueEqualsIgnoreCase(String name, String value)
      Description copied from interface: HeaderView
      Case-insensitive comparison of the first value of name against value.
      Specified by:
      valueEqualsIgnoreCase in interface HeaderView
    • contains

      public boolean contains(String name)
      Description copied from interface: HeaderView
      Whether any header named name is present.
      Specified by:
      contains in interface HeaderView
    • count

      public int count()
      Description copied from interface: HeaderView
      Total number of header lines (not distinct names — a repeated header counts once per line).
      Specified by:
      count in interface HeaderView
    • view

      public dev.relism.fpr.core.ByteView view(String name)
      Returns a zero-copy ByteView over the first value of name, or null. The returned view is drawn from a small internal SlicePool rather than allocated fresh. It stays valid until either the request ends, or view(java.lang.String) is called 4 more times on this same Http1HeaderMap — whichever comes first — at which point the ring wraps around and silently repositions the same instance over different bytes. A handler that needs more than 4 views alive at once should copy the earlier ones to String/byte[] before requesting more.
      Specified by:
      view in interface HeaderView