You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(fetch): add proxyFetch options for timeout, xfwd, changeOrigin, agent, followRedirects, HTTPS, and path merging
- Adds ProxyFetchOptions as optional 4th argument with: timeout, xfwd, changeOrigin, agent
- followRedirects (with 307/308 body replay), ssl/secure for HTTPS upstream, and addr base
- path merging via joinURL(). Also fixes multi-value request header flattening and adds
- ArrayBuffer/TypedArray/Blob body support. Wires AbortSignal via standard RequestInit.signal
Copy file name to clipboardExpand all lines: AGENTS.md
+14-3Lines changed: 14 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,13 +106,24 @@ Returns Promise<Socket> (the upstream proxy socket)
106
106
107
107
### `proxyFetch` semantics
108
108
109
-
-`proxyFetch` is HTTP-only upstream (`node:http` request); HTTPS upstream targets are not supported.
110
-
-`addr` accepts `http://host:port`, `unix:/path.sock`, or object form `{ host, port }` / `{ socketPath }`.
109
+
-`addr` accepts `http://host:port`, `https://host:port`, `unix:/path.sock`, or object form `{ host, port }` / `{ socketPath }`.
110
+
- Both HTTP and HTTPS upstream targets are supported. HTTPS is auto-detected from the `addr` string protocol.
111
+
- When `addr` is a URL string with a path (e.g. `http://host:port/api`), the path is prepended to the request path via `joinURL()`.
111
112
- Redirect mode defaults to `manual`.
112
113
- Streaming request bodies are supported (`ReadableStream`) and set `duplex: "half"`.
113
114
- Hop-by-hop response headers `transfer-encoding`, `keep-alive`, `connection` are stripped.
114
115
- Response body is `null` for `204` and `304`.
115
116
- Network and request-body-stream errors reject the Promise.
117
+
- Accepts optional `ProxyFetchOptions` as 4th argument with `timeout`, `xfwd`, `changeOrigin`, `agent`, `followRedirects`, and `ssl`.
118
+
-`timeout` sets a deadline on the upstream request; rejects with `"Proxy request timed out"` on expiry.
119
+
-`xfwd` adds `x-forwarded-for`, `x-forwarded-port`, `x-forwarded-proto`, `x-forwarded-host` derived from the input URL (not from a socket, since there is no incoming connection). Existing headers are not overwritten.
120
+
-`changeOrigin` rewrites the `Host` header to match the resolved target address (host:port for TCP, `localhost` for Unix sockets). Accounts for default ports (80 for HTTP, 443 for HTTPS).
121
+
-`agent` enables connection pooling/reuse via a custom `http.Agent`. Defaults to `false` (no agent).
122
+
-`followRedirects` enables automatic redirect following. `true` = max 5 hops; number = custom max. On 301/302/303 method changes to GET and body is dropped. On 307/308 method and body are preserved (body is buffered). Sensitive headers (`authorization`, `cookie`) are stripped on cross-origin redirects.
* Also controls certificate verification — set `rejectUnauthorized: false` to skip.
42
+
* Default: none.
43
+
*/
44
+
ssl?: Record<string,unknown>;
45
+
}
6
46
7
47
/**
8
48
* Proxy a request to a specific server address (TCP host/port or Unix socket)
9
49
* using web standard {@link Request}/{@link Response} interfaces.
10
50
*
11
-
* Note: Only plain HTTP is supported. HTTPS targets are not supported.
51
+
* Supports both HTTP and HTTPS upstream targets.
12
52
*
13
-
* @param addr - The target server address. Can be a URL string (`http://host:port`, `unix:/path`), or an object with `host`/`port` for TCP or `socketPath` for Unix sockets.
53
+
* @param addr - The target server address. Can be a URL string (`http://host:port`, `https://host:port`, `unix:/path`), or an object with `host`/`port` for TCP or `socketPath` for Unix sockets.
14
54
* @param input - The request URL (string or URL) or a {@link Request} object.
15
55
* @param inputInit - Optional {@link RequestInit} or {@link Request} to override method, headers, and body.
0 commit comments