<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>ProxyMesh Blog - node</title><link href="https://proxymesh.com/posts/" rel="alternate"/><link href="https://proxymesh.com/posts/feeds/tag-node.atom.xml" rel="self"/><id>https://proxymesh.com/posts/</id><updated>2026-11-02T00:00:00+00:00</updated><subtitle>Features, open-source releases, proxy and scraping news from ProxyMesh.</subtitle><entry><title>javascript-proxy-headers 0.4.0 keeps traffic on the proxy</title><link href="https://proxymesh.com/posts/javascript-proxy-headers-0-4-0/" rel="alternate"/><published>2026-11-02T00:00:00+00:00</published><updated>2026-11-02T00:00:00+00:00</updated><author><name>ProxyMesh</name></author><id>tag:proxymesh.com,2026-11-02:/posts/javascript-proxy-headers-0-4-0/</id><summary type="html">&lt;p&gt;javascript-proxy-headers 0.4.0 keeps got and undici on the configured proxy and returns a native ky Response. Upgrade if you use those adapters.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="https://github.com/proxymesh/javascript-proxy-headers"&gt;javascript-proxy-headers&lt;/a&gt; 0.4.0 keeps undici and got requests on the proxy you configured, and it makes the ky adapter return a native &lt;code&gt;Response&lt;/code&gt;. If you use the undici, got, or ky adapter, upgrade. Your settings and request code stay the same, except that ky users shouldn't rely on &lt;code&gt;clone()&lt;/code&gt; to copy &lt;code&gt;proxyHeaders&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;npm&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;javascript-proxy-headers@0.4.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Install the HTTP client you use too, such as &lt;code&gt;got&lt;/code&gt;, &lt;code&gt;undici&lt;/code&gt;, or &lt;code&gt;ky&lt;/code&gt;, if it isn't already in your project. Other adapters are unchanged in this release.&lt;/p&gt;
&lt;h2 id="undici-requests-no-longer-go-direct"&gt;undici requests no longer go direct&lt;/h2&gt;
&lt;p&gt;On 0.3.0, an undici request could reach the target directly instead of going through the proxy. 0.4.0 keeps that request on the CONNECT tunnel, so your call site can stay the same if you already pass &lt;code&gt;proxy&lt;/code&gt; and &lt;code&gt;proxyHeaders&lt;/code&gt;. If the proxy accepts CONNECT but doesn't forward the tunnel, 0.4.0 doesn't open a connection to the target, and the request fails with &lt;code&gt;UND_ERR_CONNECT_TIMEOUT&lt;/code&gt; once your &lt;code&gt;connectTimeout&lt;/code&gt; passes.&lt;/p&gt;
&lt;p&gt;The undici adapter also gains two options: &lt;code&gt;tlsOptions&lt;/code&gt; for the TLS connection to the target, and &lt;code&gt;connectTimeout&lt;/code&gt;, a timeout in milliseconds for the CONNECT and TLS handshake.&lt;/p&gt;
&lt;h2 id="got-now-rejects-plain-http"&gt;got now rejects plain HTTP&lt;/h2&gt;
&lt;p&gt;The got adapter is HTTPS-only. Without a guard, got uses its default HTTP agent for an &lt;code&gt;http://&lt;/code&gt; URL and connects directly, which skips the proxy. 0.4.0 rejects &lt;code&gt;http://&lt;/code&gt; URLs and HTTPS-to-HTTP redirects with a &lt;code&gt;TypeError&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;javascript-proxy-headers/got only supports HTTPS; HTTP would bypass the proxy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Your HTTPS got code doesn't need to change. If you see this error, switch the URL to &lt;code&gt;https://&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="ky-22-and-later-gets-a-response-it-accepts"&gt;ky 2.2 and later gets a Response it accepts&lt;/h2&gt;
&lt;p&gt;ky 2.2 and later requires &lt;code&gt;fetch&lt;/code&gt; to resolve with a global &lt;code&gt;Response&lt;/code&gt;, and the node-fetch &lt;code&gt;Response&lt;/code&gt; the adapter returned failed that check. 0.4.0 returns a global &lt;code&gt;Response&lt;/code&gt; with the same &lt;code&gt;proxyHeaders&lt;/code&gt; Map attached. You still need &lt;code&gt;node-fetch&lt;/code&gt;, and &lt;code&gt;createProxyKy(...)&lt;/code&gt; is still async.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;response.clone()&lt;/code&gt; doesn't copy &lt;code&gt;proxyHeaders&lt;/code&gt;. If you clone a response, read &lt;code&gt;proxyHeaders&lt;/code&gt; from the original.&lt;/p&gt;
&lt;h2 id="example-choose-a-country-and-read-the-proxy-ip"&gt;Example: choose a country and read the proxy IP&lt;/h2&gt;
&lt;p&gt;This got example sends &lt;code&gt;X-ProxyMesh-Country&lt;/code&gt; on the CONNECT request and reads the proxy's reply. Use the host and port from &lt;a href="https://docs.proxymesh.com/article/80-proxy-server-locations"&gt;Proxy Server Locations&lt;/a&gt;. &lt;code&gt;X-ProxyMesh-Country&lt;/code&gt; works only on the World and Open proxies.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;createProxyGot&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kr"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;javascript-proxy-headers/got&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;createProxyGot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;proxy&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;http://USERNAME:PASSWORD@PROXY_HOST:PORT&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;proxyHeaders&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;X-ProxyMesh-Country&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;US&amp;#39;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;https://api.ipify.org?format=json&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;proxyHeaders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;x-proxymesh-ip&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Look for the proxy IP in &lt;code&gt;response.proxyHeaders&lt;/code&gt;, not in &lt;code&gt;response.headers&lt;/code&gt;. The &lt;a href="https://docs.proxymesh.com/article/7-request-response-headers"&gt;request and response headers article&lt;/a&gt; lists every header ProxyMesh accepts and returns.&lt;/p&gt;
&lt;h2 id="coming-from-02x"&gt;Coming from 0.2.x&lt;/h2&gt;
&lt;p&gt;0.3.0 already moved the proxy's CONNECT response headers off &lt;code&gt;response.headers&lt;/code&gt;, and 0.4.0 doesn't change that. If you still read &lt;code&gt;response.headers['x-proxymesh-ip']&lt;/code&gt;, switch to &lt;code&gt;response.proxyHeaders.get('x-proxymesh-ip')&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Install it from &lt;a href="https://www.npmjs.com/package/javascript-proxy-headers/v/0.4.0"&gt;javascript-proxy-headers 0.4.0 on npm&lt;/a&gt;. The &lt;a href="https://github.com/proxymesh/javascript-proxy-headers/releases/tag/v-0.4.0"&gt;GitHub release&lt;/a&gt; and the &lt;a href="https://github.com/proxymesh/javascript-proxy-headers/compare/v-0.3.0...v-0.4.0"&gt;full diff from 0.3.0&lt;/a&gt; list the changes. The &lt;a href="https://github.com/proxymesh/javascript-proxy-headers"&gt;README and docs&lt;/a&gt; cover each adapter, and the &lt;a href="https://docs.proxymesh.com/article/41-javascript-proxy-configuration-examples"&gt;JavaScript proxy configuration examples&lt;/a&gt; show the ProxyMesh side.&lt;/p&gt;</content><category term="Releases"/><category term="release"/><category term="javascript"/><category term="node"/></entry></feed>