Skip to main content
Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.Contact Sales

Migrate hpagent to https-proxy-agent

Recipe IDorg.openrewrite.node.migrate.hpagent.migrate-hpagent-to-https-proxy-agent
Artifact@openrewrite/recipes-nodejs

Replaces the unmaintained hpagent package with https-proxy-agent. Both of hpagent's agent classes tunnel through the proxy with CONNECT, which is what https-proxy-agent does, upgrading the tunnel to TLS only for an https: target — so HttpProxyAgent and HttpsProxyAgent both become https-proxy-agent's HttpsProxyAgent. The proxy URL moves from the proxy option to the constructor's first argument, proxyRequestOptions members move up into the options object, and the dependency is swapped in each package.json that declares it, with the lock file updated to match.

Two things do not carry over, and both are reported in the HpagentManualMigrationSteps data table rather than rewritten. A TLS option set at the top level of hpagent's HttpsProxyAgent (ca, rejectUnauthorized, cert, ...) configured the handshake with the destination, because that class extends https.Agent; https-proxy-agent spends its constructor options on the connection to the proxy and takes the destination's TLS options from each request, so such an option has to move to the request or the client library. Agent options that aren't written as an object literal can't be split into the new two-argument form either. The dependency is swapped regardless, so migrate every reported site before building.

Composite recipeOpenRewritehttps-proxy-agenthpagentModerne Proprietary License
Try in PlatformTry this recipe in the Moderne platform. Not a user yet? You’ll get a no-setup demo environment, with nothing to install or configure.

Options​

2 parameters
2 optional
ParameterExampleTypeRequired
migrateSpreadOptions—StringOptional
Also migrate options that spread another object, as in {...shared, proxy: url}. Off by default, since the spread may carry a proxyRequestOptions or a destination TLS option that has to move rather than be passed through.
version^7.0.6StringOptional
The version range to declare for https-proxy-agent. The default keeps hpagent's Node 14 floor; https-proxy-agent 9 and later require Node 20.

Usage​

Run this recipe

In order to run JavaScript recipes, you will need to use the Moderne CLI. For JavaScript specific configuration instructions, please see our configuring JavaScript guide.

This recipe calls into other OpenRewrite packages as it runs. You will need to install all of the following packages before running it:

RELEASE resolves to the newest release and LATEST to the newest build of any kind, including snapshots. Either one lets mod config recipes upgrade pull in later versions without editing this command; a pinned version stays where you put it.

Install the recipe packages
mod config recipes npm install @openrewrite/recipes-nodejs
mod config recipes jar install org.openrewrite:rewrite-javascript:RELEASE

Then, you can run the recipe via:

Run the recipe
mod run . --recipe org.openrewrite.node.migrate.hpagent.migrate-hpagent-to-https-proxy-agent