HEAD Requests
HEAD isn’t an exotic method you’d think to mock — it’s one clients issue on their own initiative: HTTP libraries and CDNs probe with it before a GET, health checkers and load balancers default to it, and curl -I is the reflex when you want to see the headers a mock returns. RFC 9110 defines HEAD as GET without the body, so whenever a HEAD matches no mock of its own, Mimic answers it from the mock GET would have matched:
# Only GET /users is registered...curl -sI -o /dev/null -w '%{http_code}\n' http://localhost:8080/users # 200curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8080/users # 200- Automatic, no configuration — and an explicit
HEADmock always wins, exactly the way an explicitOPTIONSmock wins over the CORS preflight gap-filler. If you’re mocking a deliberately brokenHEAD, it serves. - Empty body, the GET’s headers. Status,
response_headers,content-typeand any CORS headers are theGET’s.Content-Lengthreports the size of the body theGETwould have sent, per RFC 9110, so a client sizing a download gets the right answer. - The GET mock’s matchers apply as usual. Query, header and body matchers are evaluated against the incoming
HEADrequest, so aGETmock that requires?page=1requires it of theHEADtoo. The fallback also works for pattern routes:HEAD /users/42is answered byGET /users/:id. - A HEAD is a call. Since the GET mock really did serve the request, its semantics follow:
delay_msapplies, the hit count increments, and asequenceadvances. AHEADbetween twoGETs on a 503-then-200 sequence consumes the 503 step — worth keeping in mind when a client probes withHEADbefore its real request. - Composes with other fallbacks.
HEAD /things/reaches a mock registered atGET /things(trailing-slash tolerance), and a CORS preflight forAccess-Control-Request-Method: HEADis answered exactly when the actualHEADwould be.
Visible in the request log
Section titled “Visible in the request log”The fallback is not magic. The request log records the request as a HEAD, under the path actually requested, with an explanation naming the GET mock that answered it:
matched mocks/users.json (score 1000: method+path 1000, HEAD answered from the GET mock at `GET:/users`)The response body is stored as a descriptor (<N bytes of … — body withheld for HEAD>), since the client never received one.
Opting out
Section titled “Opting out”Set MIMIC_HEAD_FROM_GET=false to restore the old behavior: a HEAD is answered only by an explicit HEAD mock, and gets a 404 otherwise. See Environment Variables.