Skip to content

caddyhttp: add URL pattern request matcher#7787

Open
dunglas wants to merge 1 commit into
caddyserver:masterfrom
dunglas:feat/urlpattern
Open

caddyhttp: add URL pattern request matcher#7787
dunglas wants to merge 1 commit into
caddyserver:masterfrom
dunglas:feat/urlpattern

Conversation

@dunglas
Copy link
Copy Markdown
Collaborator

@dunglas dunglas commented Jun 1, 2026

Match requests against the (quite new) URLPattern standard. This allows us to use the same syntax client-side (JS), server-side (many popular frameworks use this syntax, which is derived from Ruby routing syntax), and in Caddy.

It's also more powerful and easier to use than plain regexp.

Named groups, wildcards, and regexp components beyond are supported. Relative patterns match any origin; absolute patterns or base_url scope to scheme and host.

Exposes a url_pattern CEL function and publishes captured groups as {http.url_pattern.<component>.<group>} (similar to the JS API) placeholders.

Assistance Disclosure

I wrote the code, but I used Claude for review and to generate the tests.

Match requests against a URLPattern (https://urlpattern.spec.whatwg.org/),
supporting named groups, wildcards and regexp components beyond the path
matcher. Relative patterns match any origin; absolute patterns or base_url
scope to scheme and host.

Exposes a url_pattern CEL function and publishes captured groups as
{http.url_pattern.<component>.<group>} placeholders.
Copilot AI review requested due to automatic review settings June 1, 2026 20:33
@dunglas dunglas changed the title caddyhttp: add url_pattern request matcher caddyhttp: add URL pattern request matcher Jun 1, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new HTTP request matcher url_pattern that matches against the WHATWG URLPattern standard, exposing captured groups as placeholders and a corresponding url_pattern(...) CEL function. Supports relative patterns (which match any origin) and absolute / base_url-scoped patterns that constrain scheme + host, plus an ignore_case flag.

Changes:

  • New MatchURLPattern matcher with Caddyfile, JSON, and CEL bindings; publishes captured groups under {http.url_pattern.<component>.<group>}.
  • Unit tests covering literal/named/wildcard matching, scheme/host scoping, ignore_case, Caddyfile parsing, group placeholders, and host-independent relative matching, plus 4 new CEL integration cases.
  • Adds github.com/dunglas/go-urlpattern dependency (and transitive deps) and bumps golang.org/x/exp.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
modules/caddyhttp/urlpatternmatcher.go New matcher implementation with Provision/Match/CELLibrary/UnmarshalCaddyfile.
modules/caddyhttp/urlpatternmatcher_test.go Table-driven tests for matching behavior, Caddyfile parsing, and placeholder capture.
modules/caddyhttp/celmatcher_test.go Four new CEL test cases exercising url_pattern(...) with and without base_url.
go.mod Adds dunglas/go-urlpattern direct require and bits-and-blooms/bitset, nlnwa/whatwg-url indirects; bumps golang.org/x/exp.
go.sum Checksums for new and updated module versions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@francislavoie
Copy link
Copy Markdown
Member

As prior art, I had proposed a change to the path matcher to do some of what URLPattern allows for #4303

@francislavoie francislavoie added the feature ⚙️ New feature or request label Jun 1, 2026
@francislavoie
Copy link
Copy Markdown
Member

I'd like Caddyfile adapt test coverage as well

@francislavoie francislavoie added this to the v2.12.0 milestone Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants