Package org.mockserver.wasm
Class WasmRequest
java.lang.Object
org.mockserver.wasm.WasmRequest
Immutable view of the parts of an HTTP request that a WASM matcher module can
inspect: the
method, path, queryStringParameters,
headers, cookies, and body.
This is the input to the richer WASM ABI. Modules that export
match_request(i32 ptr, i32 len) receive a JSON envelope built from this
object; modules that export only the legacy match(i32 ptr, i32 len)
receive just the body bytes (back-compat).
Envelope version 2 added queryStringParameters and
cookies to the envelope. Because both are additive JSON fields, modules
built against version 1 (which only read method/path/headers/body) keep working
unchanged — see WasmRuntime.ENVELOPE_VERSION.
-
Constructor Summary
ConstructorsConstructorDescriptionBack-compat constructor without query parameters or cookies.WasmRequest(String method, String path, Map<String, List<String>> queryStringParameters, Map<String, List<String>> headers, Map<String, String> cookies, String body) Full constructor exposing every request part a module can inspect. -
Method Summary
Modifier and TypeMethodDescriptionstatic WasmRequestfromHttpRequest(HttpRequest request, String body) Build aWasmRequestfrom anHttpRequest, copying its method, path, query-string parameters, headers and cookies, and using the suppliedbody.getBody()getFirstHeader(String name) First value of the named header (case-insensitive), ornullif absent.getPath()static WasmRequestConvenience factory for a body-only request (legacy behaviour).withCookie(String name, String value) Adds a cookie (name to single value).withHeader(String name, String value) Adds a header value, preserving insertion order and allowing multiple values per name.withQueryStringParameter(String name, String value) Adds a query-string parameter value, preserving insertion order and allowing multiple values per name (e.g.
-
Constructor Details
-
WasmRequest
public WasmRequest(String method, String path, Map<String, List<String>> queryStringParameters, Map<String, List<String>> headers, Map<String, String> cookies, String body) Full constructor exposing every request part a module can inspect. Anynullmap argument is replaced with an empty, mutable map so the fluentwithXbuilders can always add to it. -
WasmRequest
Back-compat constructor without query parameters or cookies. Retained so existing callers keep compiling; equivalent to the full constructor with empty query/cookie maps.
-
-
Method Details
-
ofBody
Convenience factory for a body-only request (legacy behaviour). The method and path are empty and there are no query parameters, headers or cookies. -
fromHttpRequest
Build aWasmRequestfrom anHttpRequest, copying its method, path, query-string parameters, headers and cookies, and using the suppliedbody. Shared by the WASM body matcher and the response shaper so both expose an identical request envelope to a module.- Parameters:
request- the matched HTTP request (must not be null)body- the body string to expose (the matcher passes the matched body string)
-
getMethod
-
getPath
-
getQueryStringParameters
-
getHeaders
-
getCookies
-
getFirstHeader
First value of the named header (case-insensitive), ornullif absent. -
getBody
-
withHeader
Adds a header value, preserving insertion order and allowing multiple values per name. Returnsthisfor chaining. -
withQueryStringParameter
Adds a query-string parameter value, preserving insertion order and allowing multiple values per name (e.g.?id=1&id=2). Returnsthisfor chaining. -
withCookie
Adds a cookie (name to single value). A repeated name overwrites the prior value, matching HTTP cookie semantics. Returnsthisfor chaining.
-