Package dev.relism.flash.models
Class HeaderMap
java.lang.Object
dev.relism.flash.models.HeaderMap
Lazy, zero-copy header access backed directly by the request parser's byte buffer.
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.
Lifetime contract — read carefully
OneHeaderMap 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:
- Do not retain the
HeaderMapbeyond the handler. After the handler returns, the next request reuses and overwrites the buffer. AnyStringvalues retrieved viafirst(java.lang.String)/all(java.lang.String)are safe (they are independent heap copies); theHeaderMapobject itself is not. view(java.lang.String)returns a zero-copyByteViewslice into the live buffer. Storing this view and reading it after the handler returns (e.g. in an async callback, aCompletableFuturecontinuation, or a virtual-thread handoff) is a data race — the bytes may have been overwritten by the next request. Copy to aStringorbyte[]before leaving the synchronous handler scope.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionall()Returns all header values in declaration order.Returns all values of headernamein declaration order, or an empty list.Returns the first value of headername(case-insensitive), ornull.voidreset(byte[] buffer, int sectionStart, int sectionEnd) Resets this map to the header sectionbuffer[sectionStart, sectionEnd).booleanvalueEqualsIgnoreCase(String name, String value) Case-insensitive comparison of the first value ofnameagainstvalue.dev.relism.fpr.core.ByteViewReturns a zero-copyByteViewover the first value ofname, ornull.
-
Constructor Details
-
HeaderMap
public HeaderMap()
-
-
Method Details
-
reset
public void reset(byte[] buffer, int sectionStart, int sectionEnd) Resets this map to the header sectionbuffer[sectionStart, sectionEnd). -
first
Returns the first value of headername(case-insensitive), ornull. -
all
Returns all values of headernamein declaration order, or an empty list. -
all
Returns all header values in declaration order. -
valueEqualsIgnoreCase
Case-insensitive comparison of the first value ofnameagainstvalue. -
view
Returns a zero-copyByteViewover the first value ofname, ornull.
-