Package dev.relism.flash.models
Class Request
java.lang.Object
dev.relism.flash.models.Request
Immutable view of an incoming HTTP/1.1 request. Constructed by
RequestParser
and passed directly to route handlers; never modified after creation (path/query params are
injected once by the router before the handler runs).
server.get("/users/{id}", (req, res) -> {
String id = req.param("id"); // /users/42 → "42"
String page = req.query("page"); // ?page=2 → "2"
String accept = req.header("Accept"); // first Accept value
byte[] body = req.body().bytes(); // materialise body
InputStream in = req.body().stream(); // zero-copy stream
});
-
Constructor Summary
ConstructorsConstructorDescriptionRequest(RequestLine requestLine, byte[] body) Test / manual constructor —remoteAddress()returnsnull,isSecure()isfalse. -
Method Summary
Modifier and TypeMethodDescriptionbody()Returns the request body accessor.voiddrain()Discards unread body bytes; called by the server after each request on keep-alive connections.static RequestforParsed(RequestLine requestLine, InputStream stream, long contentLength, byte[] headerBuf, int bodyStart, int preBufLen, InetSocketAddress remoteAddress, SSLSocket sslSocket) Returns the first value of headername, ornullif absent.booleanheaderEquals(String name, String value) Internal: case-insensitive header value comparison used by the server keep-alive logic.headers()Returns all header values in declaration order, one entry per header line.Returns all values of headernamein declaration order.booleanisSecure()Whether this request arrived over TLS (HTTPS).method()HTTP method (GET,POST, …).Returns the path parameter namedname, ornull.path()Request path decoded as UTF-8.Returns all query parameters namednamein declaration order.Returns the first query parameter namedname, ornull.Returns the remote socket address of the connected client, ornullfor test-constructed requests.Returns the TLS session for this connection, ornullfor plain HTTP.
-
Constructor Details
-
Request
Test / manual constructor —remoteAddress()returnsnull,isSecure()isfalse.
-
-
Method Details
-
forParsed
public static Request forParsed(RequestLine requestLine, InputStream stream, long contentLength, byte[] headerBuf, int bodyStart, int preBufLen, InetSocketAddress remoteAddress, SSLSocket sslSocket) -
method
HTTP method (GET,POST, …). -
path
Request path decoded as UTF-8. Includes a leading slash; never includes the query string. Example: a request for/users/42?page=1returns"/users/42". -
header
Returns the first value of headername, ornullif absent. Lookup is case-insensitive ("content-type"and"Content-Type"are equivalent). -
headers
Returns all values of headernamein declaration order. Useful for headers that appear multiple times (e.g.Accept,Cookie). Lookup is case-insensitive. Returns an empty list if the header is absent. -
headers
Returns all header values in declaration order, one entry per header line. Useful for debugging; for targeted access preferheader(String). -
param
Returns the path parameter namedname, ornull. Parameters are declared in the route pattern (e.g./users/{id}) and injected by the router before the handler runs. Returnsnullif this route has no such parameter or the route is not parametric. -
query
Returns the first query parameter namedname, ornull. The query string is parsed lazily on the first call and cached for the request lifetime. For?a=1&a=2, returns"1". -
queries
Returns all query parameters namednamein declaration order. For?tag=a&tag=b, returns["a", "b"]. Returns an empty list if the parameter is absent. -
remoteAddress
Returns the remote socket address of the connected client, ornullfor test-constructed requests.The
InetSocketAddressis the JDK object created duringServerSocket.accept()— no allocation occurs here. To obtain the IP string (lazy, allocates once):InetSocketAddress addr = req.remoteAddress(); if (addr != null) String ip = addr.getAddress().getHostAddress(); -
isSecure
public boolean isSecure()Whether this request arrived over TLS (HTTPS). -
sslSession
Returns the TLS session for this connection, ornullfor plain HTTP. Gives access toSSLSession.getPeerCertificates()(mTLS — the caller's certificate chain, ifTlsConfig.clientAuthrequired or requested one), and toSSLSession.getCipherSuite()/SSLSession.getProtocol()for logging and diagnostics.nullrather than throwing whenisSecure()isfalse— check that first, or just null-check the result. -
body
Returns the request body accessor. UseRequestBody.bytes()to materialise the full body orRequestBody.stream()for zero-copy streaming access. The two modes are mutually exclusive per request. -
drain
public void drain()Discards unread body bytes; called by the server after each request on keep-alive connections. -
headerEquals
Internal: case-insensitive header value comparison used by the server keep-alive logic.
-