For an ordinary HTTP request through a forward proxy, Node connects to the proxy and sends the destination URL in the request line. Three values describe that one request:

ValueExample
TCP connection endpointproxy.example:8080
Request targethttp://example.com/news?q=proxy
Host headerexample.com

This Node 22 example makes the separation explicit:

const http = require('node:http');
const destination = new URL('http://example.com/news?q=proxy');

const request = http.get({
  hostname: 'proxy.example',
  port: 8080,
  path: destination.href,
  headers: { Host: destination.host },
  signal: AbortSignal.timeout(15000),
}, (response) => {
  console.log(response.statusCode);
  response.on('error', console.error);
  response.resume();
});
request.on('error', console.error);

The endpoint is a placeholder; choose a candidate from the HTTP proxy list for a public HTTP test and check its response. The example drains the response after printing its status; an application can consume the body instead. The query remains part of the request target.

Why the full URL belongs there

An origin server normally receives a target such as /news?q=proxy. A forward proxy needs the destination as well, so HTTP/1.1 defines the absolute-form target:

GET http://example.com/news?q=proxy HTTP/1.1
Host: example.com

Under the HTTP/1.1 rules, a proxy receiving absolute-form uses the URI’s authority when forwarding and replaces an inconsistent received Host field. Sending a consistent destination Host header still keeps the outgoing request unambiguous. Node’s connection hostname is the intermediary, so set the header deliberately rather than relying on that connection address.

If authentication is required, the proxy’s credentials belong to its hop. Node’s auth request option creates an Authorization header for the resource; it is not a general proxy-login option. Use the proxy’s required scheme and a suitable proxy client when the exchange is more involved.

HTTPS adds a tunnel

This example covers plain HTTP forwarding. A typical HTTPS connection through an HTTP proxy first requests CONNECT example.com:443, then starts TLS to the destination inside the accepted tunnel. Changing the example URL to HTTPS does not add those stages.

For HTTPS or a mixed workload, use a maintained proxy agent or dispatcher with the required tunnel support. For compatible Node versions, one option is Undici’s fetch with a ProxyAgent. Keep this small core-client example for cases where the plain HTTP exchange itself is what you need to control or understand.

Related articles