caddyhttp: add URL pattern request matcher#7787
Open
dunglas wants to merge 1 commit into
Open
Conversation
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.
There was a problem hiding this comment.
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
MatchURLPatternmatcher 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-urlpatterndependency (and transitive deps) and bumpsgolang.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.
Member
|
As prior art, I had proposed a change to the |
Member
|
I'd like Caddyfile adapt test coverage as well |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_urlscope to scheme and host.Exposes a
url_patternCEL 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.