Skip to content

chore: improve typing 'req'#1214

Merged
chimurai merged 1 commit intomasterfrom
improve-req-typing
Apr 25, 2026
Merged

chore: improve typing 'req'#1214
chimurai merged 1 commit intomasterfrom
improve-req-typing

Conversation

@chimurai
Copy link
Copy Markdown
Owner

@chimurai chimurai commented Apr 25, 2026

Summary by CodeRabbit

  • Refactor
    • Improved type safety for HTTP upgrade callback handling by strengthening type definitions and removing unnecessary type casts, enhancing code reliability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 25, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Type signatures across HTTP and WebSocket proxy paths are unified by removing unnecessary casts of req to TReq in error emission, updating handleUpgrade to accept the generic TReq type, and adding defensive checks for req.url presence in path rewriting logic.

Changes

Cohort / File(s) Summary
Type Signature Alignment
src/types.ts
Updated RequestHandler interface's upgrade callback to accept req parameter typed as generic TReq instead of http.IncomingMessage, narrowing the type to match the handler's generic type parameter.
Error Emission and Request Handling
src/http-proxy-middleware.ts
Removed unnecessary type casts of req to TReq in error code paths for both HTTP and WebSocket proxies; updated handleUpgrade signature to use TReq; added defensive req.url presence check in path rewriting before invoking rewriter.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • PR #1197: Modifies the same request-typing surfaces in src/http-proxy-middleware.ts and src/types.ts, aligning method signatures to use the generic TReq type consistently.

Poem

🐰 With types now unified, clean and bright,
No needless casts to cloud the sight,
The rabbit hops through safer code,
Where TReq flows the proper road!
Generic peace at last, hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: improve typing 'req'' directly and accurately summarizes the main change: improving type safety for the req parameter across the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improve-req-typing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 25, 2026

npm i https://pkg.pr.new/http-proxy-middleware@1214

commit: d84bbdf

@chimurai chimurai merged commit 5d28676 into master Apr 25, 2026
19 of 20 checks passed
@chimurai chimurai deleted the improve-req-typing branch April 25, 2026 20:20
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 94.78%. remained the same — improve-req-typing into master

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.

2 participants