Package org.mockserver.responseheaders
Class DefaultResponseHeaders
java.lang.Object
org.mockserver.responseheaders.DefaultResponseHeaders
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefaultResponseHeaders(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).booleanisEmpty()Parses the configureddefaultResponseHeadersvalue (a pipe-separated list ofname=valuepairs) into an immutable list ofHeaders.
-
Constructor Details
-
DefaultResponseHeaders
-
-
Method Details
-
parse
Parses the configureddefaultResponseHeadersvalue (a pipe-separated list ofname=valuepairs) into an immutable list ofHeaders. 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 benullor blank- Returns:
- an immutable list of parsed headers (empty when the value is blank)
-
isEmpty
public boolean isEmpty() -
addDefaultResponseHeaders
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
-