Skip to content

Add 'header value containing' matcher & header-value match-and-replace transform#249

Draft
komen205 wants to merge 3 commits into
httptoolkit:mainfrom
komen205:header-includes-matcher
Draft

Add 'header value containing' matcher & header-value match-and-replace transform#249
komen205 wants to merge 3 commits into
httptoolkit:mainfrom
komen205:header-includes-matcher

Conversation

@komen205

Copy link
Copy Markdown

Summary

Adds substring-level header matching and a header-value match-and-replace transform, so rules can target part of a header value instead of requiring the whole value to match exactly. The motivating case is a multi-cookie Cookie header, where today you can't match (or rewrite) a single cookie without touching the rest.

This is the UI side of the change. It pairs with the Mockttp header-includes matcher / matchReplaceHeaders transform (see the corresponding httptoolkit-server PR, which currently points at a locally-built mockttp 4.4.2 until that release ships).

What's new

  • "Header value containing" matcher — matches when a given header's value contains a substring, rather than requiring the entire value to match exactly (as the existing "with headers including" matcher does). This makes it possible to match one cookie within a multi-cookie Cookie header.
    • First implemented UI-side on Mockttp's callback matcher (no server change required).
    • Then promoted to a real header-includes matcher in Mockttp itself, so it's evaluated server-side like every other matcher. This removes the per-request round-trip and the need for the UI to stay connected for matching to work.
  • "Match & replace text in a header value" transform — a third option in the headers transform dropdown that rewrites patterns within a header's value (via mockttp's matchReplaceHeaders) without replacing the whole header. Handy for rewriting one cookie's value inside a combined Cookie header.

Notes

  • Depends on the new Mockttp matcher/transform; until that's released, package.json is pinned to a local mockttp 4.4.2 build.
  • Opened as a draft for early feedback on the approach (callback matcher → first-class matcher migration, and the transform UX).

Tests

  • test/unit/model/header-includes-matcher.spec.ts
  • test/unit/model/transform-serialization.spec.ts

komen205 and others added 3 commits June 11, 2026 16:20
The existing 'with headers including' matcher requires the entire header
value to match exactly, which makes it impossible to match one cookie
within a multi-cookie Cookie header. This adds a new matcher that checks
whether a given header's value contains a given substring, built on
Mockttp's callback matcher so it needs no server-side changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replaces the UI-side callback-based matcher with the proper pattern: a
real 'header-includes' matcher implemented in mockttp itself, evaluated
server-side like all other matchers. This removes the need for the UI
to stay connected for matching, and the per-request round-trip.

Uses a locally-built mockttp 4.4.2 until that change is released.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds a third option to the headers transform dropdown: 'Match & replace
text in a header value', configuring mockttp's new matchReplaceHeaders
transform. This rewrites patterns within a header's value (e.g. one
cookie's value inside a multi-cookie Cookie header) without replacing
the whole header.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedmockttp@​4.4.0 ⏵ 4.4.200000

View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant