Class DefaultResponseHeaders

java.lang.Object
org.mockserver.responseheaders.DefaultResponseHeaders

public class DefaultResponseHeaders extends Object
Applies the configured defaultResponseHeaders to outgoing responses that MockServer returns, using add-if-absent semantics so any header explicitly set on the matched response always wins.

The configured value is a pipe (|) separated list of name=value pairs, e.g. Server=MockServer|X-Trace-Id=abc123. A header value may itself contain commas; only | separates headers and only the first = in each pair separates the name from the value. Empty segments, segments without an =, and segments with a blank name are skipped.

Author:
jamesdbloom
  • Constructor Details

    • DefaultResponseHeaders

      public DefaultResponseHeaders(Configuration configuration)
  • Method Details

    • parse

      public static List<Header> parse(String configuredValue)
      Parses the configured defaultResponseHeaders value (a pipe-separated list of name=value pairs) into an immutable list of Headers. Empty segments, segments without an =, and segments with a blank name are skipped.

      This is the single source of truth for the parse; callers are expected to memoise the result (see Configuration.parsedDefaultResponseHeaders()) rather than invoke it per request.

      Parameters:
      configuredValue - the raw configured value, may be null or blank
      Returns:
      an immutable list of parsed headers (empty when the value is blank)
    • isEmpty

      public boolean isEmpty()
    • addDefaultResponseHeaders

      public void addDefaultResponseHeaders(HttpResponse response)
      Adds each configured default header to the response only if the response does not already contain a header with that name (case-insensitive). A header explicitly set on the matched response therefore always wins.
      Parameters:
      response - the response MockServer is about to return