Skip to content

fix: precompile x-forwarded-host regexp#1203

Merged
ferhatelmas merged 2 commits into
masterfrom
ferhat/x-forward
Jul 6, 2026
Merged

fix: precompile x-forwarded-host regexp#1203
ferhatelmas merged 2 commits into
masterfrom
ferhat/x-forward

Conversation

@ferhatelmas

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

In multitenant, if x-forwarded-host regex is given, it's compiled twice per request.

What is the new behavior?

Precompile it once and cache module level to cut down two compilation in hot path.

Copilot AI review requested due to automatic review settings July 6, 2026 08:05
@ferhatelmas ferhatelmas requested a review from a team as a code owner July 6, 2026 08:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduces per-request overhead in multitenant mode by precompiling the configured X-Forwarded-Host regular expression once and reusing it, avoiding repeated RegExp construction in hot paths.

Changes:

  • Introduces getXForwardedHostRegExp with a module-level cache keyed by the configured pattern string.
  • Updates multitenant tenant-id extraction and tracing hooks to use the compiled RegExp instead of a pattern string.
  • Adds unit tests to verify caching, recompilation on pattern changes, and behavior with invalid patterns.

Reviewed changes

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

Show a summary per file
File Description
src/internal/monitoring/otel-tracing.ts Uses a precompiled/cached RegExp for multitenant tenant extraction in incoming span hook.
src/internal/http/x-forwarded-host.ts Adds helper to compile and cache the X-Forwarded-Host regex once per pattern value.
src/internal/http/x-forwarded-host.test.ts Adds tests covering cache reuse, recompilation, and invalid-pattern behavior.
src/internal/http/index.ts Re-exports the new x-forwarded-host module from the internal HTTP barrel.
src/internal/database/client.ts Uses cached compiled RegExp for host checking instead of compiling per call.
src/http/plugins/tenant-id.ts Uses precompiled/cached RegExp for tenant-id derivation from x-forwarded-host.

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

@coveralls

coveralls commented Jul 6, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28780172781

Coverage increased (+0.01%) to 78.857%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (20 of 22 lines covered, 90.91%).
  • 3 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
src/internal/monitoring/otel-tracing.ts 3 1 33.33%
Total (4 files) 22 20 90.91%

Coverage Regressions

3 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/storage/protocols/tus/s3-locker.ts 3 78.37%

Coverage Stats

Coverage Status
Relevant Lines: 12249
Covered Lines: 10102
Line Coverage: 82.47%
Relevant Branches: 7043
Covered Branches: 5111
Branch Coverage: 72.57%
Branches in Coverage %: Yes
Coverage Strength: 420.82 hits per line

💛 - Coveralls

Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
@ferhatelmas ferhatelmas merged commit 2258734 into master Jul 6, 2026
26 checks passed
@ferhatelmas ferhatelmas deleted the ferhat/x-forward branch July 6, 2026 09:12
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.

4 participants