Class WasmRequest

java.lang.Object
org.mockserver.wasm.WasmRequest

public class WasmRequest extends Object
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 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. Any null map argument is replaced with an empty, mutable map so the fluent withX builders can always add to it.
    • WasmRequest

      public WasmRequest(String method, String path, Map<String,List<String>> headers, String body)
      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

      public static WasmRequest ofBody(String body)
      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

      public static WasmRequest fromHttpRequest(HttpRequest request, String body)
      Build a WasmRequest from an HttpRequest, copying its method, path, query-string parameters, headers and cookies, and using the supplied body. 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

      public String getMethod()
    • getPath

      public String getPath()
    • getQueryStringParameters

      public Map<String,List<String>> getQueryStringParameters()
    • getHeaders

      public Map<String,List<String>> getHeaders()
    • getCookies

      public Map<String,String> getCookies()
    • getFirstHeader

      public String getFirstHeader(String name)
      First value of the named header (case-insensitive), or null if absent.
    • getBody

      public String getBody()
    • withHeader

      public WasmRequest withHeader(String name, String value)
      Adds a header value, preserving insertion order and allowing multiple values per name. Returns this for chaining.
    • withQueryStringParameter

      public WasmRequest withQueryStringParameter(String name, String value)
      Adds a query-string parameter value, preserving insertion order and allowing multiple values per name (e.g. ?id=1&id=2). Returns this for chaining.
    • withCookie

      public WasmRequest withCookie(String name, String value)
      Adds a cookie (name to single value). A repeated name overwrites the prior value, matching HTTP cookie semantics. Returns this for chaining.