Skip to content

🔥 feat: Add support for configuring the Regex engine on the router#4254

Open
Claude wants to merge 17 commits intomainfrom
claude/add-alternative-regex-support
Open

🔥 feat: Add support for configuring the Regex engine on the router#4254
Claude wants to merge 17 commits intomainfrom
claude/add-alternative-regex-support

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented May 4, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>📝 [Proposal]: ability to use alternative regex for router</issue_title>
<issue_description>### Feature Proposal Description

This is a substantially faster assembly optimised regex package that is drop in replacement: https://github.com/coregx/coregex

Alignment with Express API

Na

HTTP RFC Standards Compliance

Na

API Stability

Na

Feature Examples

Na

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.</issue_description>

Comments on the Issue (you are @claude[agent] in this section)

@Claude Claude AI assigned Claude and gaby May 4, 2026
@Claude Claude AI linked an issue May 4, 2026 that may be closed by this pull request
3 tasks
@ReneWerner87 ReneWerner87 added this to v3 May 4, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone May 4, 2026
- Created RegexEngine and RegexCompiler interfaces
- Updated path.go to use configured regex engine
- Added RegexEngine field to Config with DefaultRegexEngine
- Updated router.go to pass RegexEngine to parseRoute
- Added comprehensive tests for regex abstraction
- Created example showing how to integrate coregex

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/3e2b7990-e9c5-41f6-afbf-ad29c8bbcfd0

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.14%. Comparing base (7bfb06a) to head (4d138de).

Files with missing lines Patch % Lines
path.go 88.88% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4254      +/-   ##
==========================================
- Coverage   91.16%   91.14%   -0.02%     
==========================================
  Files         127      127              
  Lines       12605    12641      +36     
==========================================
+ Hits        11491    11522      +31     
- Misses        697      701       +4     
- Partials      417      418       +1     
Flag Coverage Δ
unittests 91.14% <92.30%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Claude AI and others added 2 commits May 4, 2026 23:03
- Added regex-engines.md guide with coregex integration examples
- Documented RegexEngine and RegexCompiler interfaces
- Included performance benchmarks and use cases
- Added custom implementation examples

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/3e2b7990-e9c5-41f6-afbf-ad29c8bbcfd0

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Claude finished work on behalf of gaby May 4, 2026 23:06
@Claude Claude AI requested a review from gaby May 4, 2026 23:06
@gaby
Copy link
Copy Markdown
Member

gaby commented May 4, 2026

@claude[agent]

  • fix markdownlint issues
  • remove examples folder

- Removed examples/regex-engine folder as requested
- Updated docs/guide/regex-engines.md to remove reference to examples folder
- All markdown linting issues resolved

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/9e71d891-0cc3-4786-8921-d994e500db6f

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
@Claude
Copy link
Copy Markdown
Contributor Author

Claude AI commented May 4, 2026

@claude[agent]

  • fix markdownlint issues
  • remove examples folder

Fixed in d7629bf:

  • Removed examples/regex-engine folder
  • Fixed markdown linting issues in docs/guide/regex-engines.md
  • All markdown lint checks now pass

Claude finished work on behalf of gaby May 4, 2026 23:29
@gaby
Copy link
Copy Markdown
Member

gaby commented May 5, 2026

@claude[agent] I'm not sure about the addition of regex.go. It seems like it might be over-engineered.

I believe the approach should be as straightforward as our JSONEncoder and Decoder implementations within the app configuration.

Moved regex types from separate regex.go file into path.go where they are used. This follows the simpler pattern similar to JSONEncoder/Decoder and reduces over-engineering by keeping related code together.

Changes:
- Removed regex.go and moved RegexEngine/RegexCompiler types to path.go
- Moved tests from regex_test.go to path_test.go
- All tests pass, no linting issues

Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/175129f3-3f03-4a29-9673-b0521797d587

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
@Claude
Copy link
Copy Markdown
Contributor Author

Claude AI commented May 5, 2026

@claude[agent] I'm not sure about the addition of regex.go. It seems like it might be over-engineered.

I believe the approach should be as straightforward as our JSONEncoder and Decoder implement...

Simplified in ffc10c3. Removed the separate regex.go file and moved all regex types directly into path.go where they're actually used. This follows a simpler pattern similar to other encoders/decoders and keeps related code together. The abstraction is now more minimal while still providing the flexibility to use alternative regex engines.

Claude finished work on behalf of gaby May 5, 2026 02:11
@gaby
Copy link
Copy Markdown
Member

gaby commented May 5, 2026

@claude[agent] Looking at the guide docs/guide/regex-engines.md and code. Using a different regex library is too complicated. We can simplify this.

Following feedback to simplify the regex engine abstraction, this commit
refactors the implementation to use a simple function type instead of
interface-based approach.

Key changes:
- Replace RegexEngine interface with RegexHandler function type
- RegexHandler is now: func(pattern string) RegexCompiler
- Add defaultRegexHandler function that wraps regexp.MustCompile
- Update all references from RegexEngine to RegexHandler
- Simplify documentation to show direct usage without adapter types

This follows the same pattern as JSONEncoder/JSONDecoder in the codebase,
making it much simpler for users to adopt alternative regex engines:

Before (required adapter types):
    type CoregexEngine struct{}
    func (CoregexEngine) MustCompile(pattern string) fiber.RegexCompiler {...}
    app := fiber.New(fiber.Config{RegexEngine: CoregexEngine{}})

After (just a function):
    app := fiber.New(fiber.Config{
        RegexHandler: func(pattern string) fiber.RegexCompiler {
            return coregex.MustCompile(pattern)
        },
    })

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
Claude finished work on behalf of gaby May 5, 2026 02:40
@gaby
Copy link
Copy Markdown
Member

gaby commented May 5, 2026

@claude[agent] Why are you adding a handler, instead of just using coregex.MustCompile. Stdlib and coregex use the same API.

// stdlib
re := regexp.MustCompile(pattern)

// coregex — same API
re := coregex.MustCompile(pattern)

The app config option should just take coregex.MustCompile, i think?

Claude finished work on behalf of gaby May 5, 2026 04:56
@gaby gaby changed the title [WIP] Add ability to use alternative regex for router 🔥 feat: Add support for configuring the Regex engine on the router May 6, 2026
@gaby gaby marked this pull request as ready for review May 6, 2026 02:06
@gaby gaby requested a review from a team as a code owner May 6, 2026 02:06
Copy link
Copy Markdown
Contributor

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

This PR adds a new fiber.Config.RegexHandler extension point so route regex() constraints can be compiled with a configurable regex engine instead of always using the standard library. It fits into Fiber’s router/path parsing layer by threading the configured compiler through route registration and RoutePatternMatch.

Changes:

  • Add Config.RegexHandler with a default of regexp.MustCompile, and pass it into route parsing during route registration and prefixing.
  • Generalize regex constraint compilation in path.go so compiled regex matchers are stored behind an interface.
  • Add tests and a new guide page describing alternative regex engine usage, plus a number of formatting-only updates in unrelated files.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
router.go Passes app.config.RegexHandler into route parsing during registration/prefixing.
router_test.go Updates direct parseRoute call sites to the new signature.
prefork.go Formatting-only change.
path.go Introduces RegexHandler/RegexCompiler and uses them for regex() constraints and RoutePatternMatch.
path_test.go Updates parser tests and adds new coverage for configurable regex handlers.
middleware/logger/default_logger.go Formatting-only change.
middleware/envvar/envvar_test.go Formatting-only change.
middleware/compress/compress.go Formatting-only change.
helpers.go Formatting-only change.
helpers_test.go Formatting-only change.
domain_test.go Formatting-only change.
docs/guide/regex-engines.md Adds user-facing documentation for alternative regex engines.
ctx_test.go Formatting-only change.
client/request_test.go Formatting-only change.
client/client_test.go Formatting-only change.
app.go Adds the new public Config.RegexHandler field and its default initialization.

Comment thread path.go Outdated
Comment thread path.go Outdated
Comment thread app.go Outdated
Comment thread docs/guide/regex-engines.md Outdated
Comment thread docs/guide/regex-engines.md Outdated
Comment thread app.go Outdated
Comment thread path_test.go
Comment thread docs/guide/regex-engines.md Outdated
gaby and others added 2 commits May 5, 2026 22:14
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@gaby
Copy link
Copy Markdown
Member

gaby commented May 6, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

@copilot apply changes based on the comments in this thread

Applied the review-thread follow-ups in 4d138de. RegexHandler is now validated up front, the matcher contract is reduced to MatchString, failure-mode coverage was added, and the API/guide docs were updated to document the final behavior and concurrency requirement. make lint, make test, and make markdown pass; make audit is still blocked by existing Go 1.25 stdlib govulncheck findings in the environment.

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Comment thread path.go
Comment on lines +62 to +66
if handlerType.Kind() != reflect.Func || handlerValue.IsNil() {
panic("fiber: Config.RegexHandler must be a non-nil function")
}
if handlerType.NumIn() != 1 || handlerType.In(0).Kind() != reflect.String || handlerType.NumOut() != 1 {
panic("fiber: Config.RegexHandler must have signature func(string) T")
Comment thread path.go Outdated
// segment when matching incoming requests.
type Constraint struct {
RegexCompiler *regexp.Regexp
RegexCompiler RegexCompiler
@gaby
Copy link
Copy Markdown
Member

gaby commented May 6, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

@copilot apply changes based on the comments in this thread

Applied the follow-up changes in 67f902d. RegexHandler now enforces the exact documented func(string) T signature so named-string inputs fail fast, and Constraint.RegexCompiler is back to *regexp.Regexp for compatibility while non-stdlib matchers are stored internally. Targeted regex tests pass, and the full local validation set passes except for the same pre-existing local make audit govulncheck/toolchain findings; the current branch CI workflows are green.

Copilot finished work on behalf of gaby May 6, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

📝 [Proposal]: ability to use alternative regex for router

5 participants