Quick answer: In Mockoon, header matching is a response rule. On a route response's Rules tab, set the target to Header, enter a name such as Authorization or Accept, choose an operator like equals, regex match or null, and provide a value. Mockoon walks responses in declared order and serves the first whose rule group matches. Rules inside one response use OR by default and can switch to AND. Header rules choose a prepared response; they do not change which path and method route matches.
How evaluation order works
Mockoon checks a route's responses top to bottom and serves the first whose group is true. Rules within one response default to OR; the OR/AND toggle makes them require every condition. The exclamation mark inverts a single rule, turning a null check into "header is present." Drag to reorder.
Ordering causes most "rule ignored" reports. A broad response with no rules, or a loose regex placed above a specific header response, matches first and shadows it. Keep specific conditions first and the permissive default last. The rules-disabled toggle forces the default response and cannot combine with sequential or random mode.
Common header recipes
The header name is the property field, and the value is plain text or a regex without leading or trailing slashes.
| Goal | Operator and header | Value approach |
|---|---|---|
| Return 401 when Authorization is missing | null on Authorization | Null means absent or null; place this response first |
| Require a bearer token prefix | regex match on Authorization | Use ^Bearer .+ to check shape, not validity |
| Content negotiation on Accept | regex match on Accept | An unanchored pattern such as application/vnd.api\+json tolerates parameters |
| Match JSON regardless of charset | regex match on Content-Type | Use application/json rather than exact equals, since ; charset=utf-8 may be appended |
| Branch on a feature or tenant header | equals or regex on X-Feature or X-Tenant
|
Equals is case- and whitespace-sensitive, so regex tolerates variants |
For a header with multiple values, array includes checks whether a value is present in the resolved array. Inverting one condition is often clearer than writing a negative regex.
Operators and the empty-header distinction
The operators are equals, regex match, null, empty array, array includes and valid JSON schema, though not every target supports each one. For headers the useful set is equals, regex match, null and, for array values, array includes.
Two empty states differ. Null matches a header that is absent or null. A present header with an empty string is not null; match it with ^$ or the whitespace pattern ^$|\s+. Regex is unanchored unless you add ^ and $, so json matches anywhere. Names and values also accept templating helpers for dynamic rules.
What header rules cannot do
Header rules run after routing. Path, method, route parameters and query matching choose the route; a header cannot move a request to another one, and a wrong path returns 404 before header rules run.
They compare strings, not credentials. A ^Bearer .+ rule checks a prefix, not signature, expiry or issuer, so treat the branch as a client fixture rather than a security control. Equals is exact, which is why casing, whitespace and charset parameters call for regex.
If no response rule matches, the default response is skipped and route-level fallback can forward the request to a proxy target. The request log then shows whether the response was local or proxied, separating a routing miss from a rule miss.
Powerduck approaches header-dependent flows from the verification side. Its scenario runner sends an ordered request sequence, asserts status, headers and response fields at each step, and passes values between requests, then exports an HTML report. That checks a header contract across a flow rather than only configuring isolated branches. The broader comparison with standalone mock servers is in our comparison hub.
Frequently asked questions
Are header names case-sensitive? Header names follow normal HTTP case-insensitivity. Values do not: equals is exact, so use regex to tolerate casing, whitespace or parameters.
How do I match a missing header? Use the null operator. To require the header, invert that null rule or use a regex such as .+.
Why does the default response always win? Responses are evaluated top to bottom and the first match is served. Move specific responses above the catch-all, check OR versus AND, and confirm rules are not disabled.
The bottom line
Treat header matching as ordered response selection, not routing or authentication. Put specific rules first, use null for absent headers and regex for values with optional parameters, then confirm the choice in the request log. A mock rule proves your client handles a branch; it does not prove the token is valid or that the real backend enforces the same condition.
Top comments (0)