Skip to content

refactor(#1136): replace http-proxy w/ httpxy#1160

Merged
chimurai merged 8 commits intochimurai:masterfrom
SukkaW:replace-http-proxy
Apr 3, 2026
Merged

refactor(#1136): replace http-proxy w/ httpxy#1160
chimurai merged 8 commits intochimurai:masterfrom
SukkaW:replace-http-proxy

Conversation

@SukkaW
Copy link
Copy Markdown
Contributor

@SukkaW SukkaW commented Feb 7, 2026

Description

Another attempt to fix #1136.

Unlike #1159, instead of replacing http-proxy w/ http-proxy-3, the PR chooses httpxy, because:

Motivation and Context

See #1136

How has this been tested?

image image image

Unlike #1159, I actually get all the tests to pass and TypeScript happy! You can check the action log here: SukkaW#1

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@SukkaW
Copy link
Copy Markdown
Contributor Author

SukkaW commented Feb 7, 2026

cc @chimurai

Please check my PR as another attempt to fix #1136. Unlike #1159, I get all the tests to pass both on my machine locally and on CI (check SukkaW#1):

image image

Also, I get rid of all TypeScript errors with tsc --build runs perfectly:

image

@chimurai
Copy link
Copy Markdown
Owner

chimurai commented Feb 7, 2026

Hi @SukkaW

Thanks for the PR! Didn't know about httpxy

Did a quick check and looks really nice so far. Most of the types are working.

Found a small issue in the typing where req somehow is now type any.

image

Added an extra check to prevent req: any (#1161)
image

🔧 Can you rebase with master?
You'll see the same error in:

// responseInterceptor
proxyServer.on(
'proxyRes',
responseInterceptor(async (buffer, proxyRes, req, res) => {
req.params;
res.status(200).send('OK');
return buffer;
}),
);

Comment thread tsconfig.json
@SukkaW
Copy link
Copy Markdown
Contributor Author

SukkaW commented Feb 8, 2026

Did a quick check and looks really nice so far. Most of the types are working.

Found a small issue in the typing where req somehow is now type any.

The httpxy usage of EventEmitter is not typed. I have submitted a PR to the upstream to fix it: unjs/httpxy#96

After httpxy merges that PR and releases a new version, the any we are seeing here should be gone.

@SukkaW SukkaW force-pushed the replace-http-proxy branch from b1801dd to c10521e Compare February 9, 2026 09:09
@SukkaW
Copy link
Copy Markdown
Contributor Author

SukkaW commented Feb 11, 2026

@chimurai

The types are fixed, and all tests passed on my machine locally:

image

Comment thread src/handlers/response-interceptor.ts
Comment thread src/plugins/default/error-response-plugin.ts
@SukkaW
Copy link
Copy Markdown
Contributor Author

SukkaW commented Feb 11, 2026

@chimurai Also, I am currently actively working on httpxy's HTTP/2 listener support (unjs/httpxy#38).

Update: almost done unjs/httpxy#102

@SukkaW
Copy link
Copy Markdown
Contributor Author

SukkaW commented Mar 5, 2026

@chimurai Hello, what else is required for the PR to merge? All TypeScript error has been fixed and the lint is now happy.

@SukkaW
Copy link
Copy Markdown
Contributor Author

SukkaW commented Apr 2, 2026

@chimurai Just a friendly ping, would you like to review this? All TypeScript errors have been fixed, the lint is happy, and all the tests have passed.

@chimurai chimurai force-pushed the replace-http-proxy branch from 13848fb to 548b23c Compare April 2, 2026 17:26
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 2, 2026

Coverage Status

coverage: 96.544% (-0.6%) from 97.15%
when pulling eb2449c on SukkaW:replace-http-proxy
into bcf1864 on chimurai:master.

@chimurai
Copy link
Copy Markdown
Owner

chimurai commented Apr 2, 2026

Hi @SukkaW. Thanks for the reminder. PR looks good.

CI is failing because patches need to be removed which are not needed anymore:

patches/http-proxy+1.18.1.patch

You can verify if the other patches are still needed with:

yarn patch-package

Once this is fixed, this PR can be merged 👍

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

This PR attempts to resolve #1136 by replacing the unmaintained http-proxy dependency with httpxy, updating the middleware implementation and exported types to match httpxy’s API/behavior.

Changes:

  • Swap http-proxy / @types/http-proxy for httpxy and update lockfile/spellcheck dictionary.
  • Refactor core proxying logic to use httpxy’s promise-based web/ws APIs and adjust error handling + shutdown behavior.
  • Update public TypeScript types and response interception types to align with the new proxy library.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json Replaces proxy dependency with httpxy (but note patch-package implications).
yarn.lock Removes http-proxy transitive deps and adds httpxy.
tsconfig.json Enables skipLibCheck.
src/http-proxy-middleware.ts Migrates to httpxy (createProxyServer, async web/ws), adjusts error emitting and close handling.
src/types.ts Switches exported proxy types from http-proxy to httpxy and redefines event callback shapes.
src/plugins/default/proxy-events.ts Adjusts on option iteration to improve typing/narrowing.
src/plugins/default/error-response-plugin.ts Changes error guard condition for rethrow behavior.
src/handlers/response-interceptor.ts Corrects proxyRes typing to http.IncomingMessage and updates decompression call site.
cspell.json Adds httpxy to allowed words list.

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

Comment thread src/types.ts
Comment thread package.json
Comment thread src/plugins/default/error-response-plugin.ts
Comment thread package.json
@SukkaW SukkaW force-pushed the replace-http-proxy branch from 548b23c to dacea34 Compare April 3, 2026 06:10
@SukkaW
Copy link
Copy Markdown
Contributor Author

SukkaW commented Apr 3, 2026

cc @chimurai

I have rebased the PR to the latest master, and I have dropped patches/http-proxy+1.18.1.patch in dacea34 (this PR).

@erictheswift
Copy link
Copy Markdown

Kudos!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 3, 2026

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

commit: 058d409

@chimurai chimurai added this to the v4 milestone Apr 3, 2026
@chimurai chimurai enabled auto-merge (squash) April 3, 2026 21:11
@chimurai chimurai force-pushed the replace-http-proxy branch from dacea34 to eb2449c Compare April 3, 2026 21:14
@chimurai chimurai merged commit 42d25d4 into chimurai:master Apr 3, 2026
10 checks passed
@chimurai
Copy link
Copy Markdown
Owner

chimurai commented Apr 3, 2026

Many thanks @SukkaW and @bjohansebas (with the previous attempt) for helping out with the upgrade.

Special thanks to @pi0 for the continuation of http-proxy with httpxy 🎉

You guys made a long waited upgrade possible 🙏


I published a beta version: npm i http-proxy-middleware@beta

Please let me know if there are any issues.

@chimurai
Copy link
Copy Markdown
Owner

chimurai commented Apr 4, 2026 via email

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.

feat: migrate from http-proxy to http-proxy alternative

6 participants