MCPcopy Create free account
hub / github.com/codeaashu/claude-code / getUpstreamProxyEnv

Function getUpstreamProxyEnv

src/upstreamproxy/upstreamproxy.ts:160–199  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

158 * the same recipe.
159 */
160export function getUpstreamProxyEnv(): Record<string, string> {
161 if (!state.enabled || !state.port || !state.caBundlePath) {
162 // Child CLI processes can't re-initialize the relay (token file was
163 // unlinked by the parent), but the parent's relay is still running and
164 // reachable at 127.0.0.1:<port>. If we inherited proxy vars from the
165 // parent (HTTPS_PROXY + SSL_CERT_FILE both set), pass them through so
166 // our subprocesses also route through the parent's relay.
167 if (process.env.HTTPS_PROXY && process.env.SSL_CERT_FILE) {
168 const inherited: Record<string, string> = {}
169 for (const key of [
170 'HTTPS_PROXY',
171 'https_proxy',
172 'NO_PROXY',
173 'no_proxy',
174 'SSL_CERT_FILE',
175 'NODE_EXTRA_CA_CERTS',
176 'REQUESTS_CA_BUNDLE',
177 'CURL_CA_BUNDLE',
178 ]) {
179 if (process.env[key]) inherited[key] = process.env[key]
180 }
181 return inherited
182 }
183 return {}
184 }
185 const proxyUrl = `http://127.0.0.1:${state.port}`
186 // HTTPS only: the relay handles CONNECT and nothing else. Plain HTTP has
187 // no credentials to inject, so routing it through the relay would just
188 // break the request with a 405.
189 return {
190 HTTPS_PROXY: proxyUrl,
191 https_proxy: proxyUrl,
192 NO_PROXY: NO_PROXY_LIST,
193 no_proxy: NO_PROXY_LIST,
194 SSL_CERT_FILE: state.caBundlePath,
195 NODE_EXTRA_CA_CERTS: state.caBundlePath,
196 REQUESTS_CA_BUNDLE: state.caBundlePath,
197 CURL_CA_BUNDLE: state.caBundlePath,
198 }
199}
200
201/** Test-only: reset module state between test cases. */
202export function resetUpstreamProxyForTests(): void {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected