Skip to content

API mock interceptor: XHR header case sensitivity in request matching #124

Description

@tyevco

Summary

The API mock interceptor stores XHR request headers with their original case but the matcher attempts case-insensitive lookup with an incomplete fallback.

Current Behavior

In interceptor.ts (line 205):

request.headers[name] = value;  // stores with original case, e.g. "Content-Type"

In matcher.ts (line 37):

const requestHeaderValue = request.headers[key.toLowerCase()] || request.headers[key];

This fallback only works when the mock rule's header name matches either the lowercased or exact-case version of the stored header. It fails when the cases don't align in either direction.

Example Failure

Mock rule: { headers: { "content-type": "application/json" } }
Stored header: request.headers["Content-Type"] = "application/json"

Lookup:

  • request.headers["content-type"]undefined (stored as Content-Type)
  • request.headers["content-type"]undefined (same key, same result)

The header match fails even though semantically it should match.

Suggested Fix

Normalize headers to lowercase on storage:

request.headers[name.toLowerCase()] = value;

Or use a case-insensitive lookup helper in the matcher.

Priority

Low — most XHR libraries use standard casing (Content-Type, Authorization) which would match the typical mock rule casing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions