{"author":{"name":"Gajus Kuizinas","email":"gajus@gajus.com","url":"http://gajus.com"},"ava":{"babel":{"compileAsTests":["test/helpers/**/*"]},"files":["test/global-agent/**/*"],"require":["@babel/register"]},"dependencies":{"boolean":"^3.0.1","core-js":"^3.6.5","es6-error":"^4.1.1","matcher":"^3.0.0","roarr":"^2.15.3","semver":"^7.3.2","serialize-error":"^7.0.1"},"description":"Global HTTP/HTTPS proxy configurable using environment variables.","devDependencies":{"@ava/babel":"^1.0.1","@babel/cli":"^7.10.1","@babel/core":"^7.10.2","@babel/node":"^7.10.1","@babel/plugin-transform-flow-strip-types":"^7.10.1","@babel/preset-env":"^7.10.2","@babel/register":"^7.10.1","anyproxy":"^4.1.2","ava":"^3.8.2","axios":"^0.19.2","babel-plugin-istanbul":"^6.0.0","babel-plugin-transform-export-default-name":"^2.0.4","coveralls":"^3.1.0","eslint":"^7.1.0","eslint-config-canonical":"^20.0.5","flow-bin":"^0.125.1","flow-copy-source":"^2.0.9","get-port":"^5.1.1","got":"^11.1.4","husky":"^4.2.5","nyc":"^15.1.0","pem":"^1.14.4","request":"^2.88.2","semantic-release":"^17.0.8","sinon":"^9.0.2"},"engines":{"node":">=10.0"},"husky":{"hooks":{"pre-commit":"npm run lint && npm run test && npm run build"}},"keywords":["http","global","proxy","agent"],"license":"BSD-3-Clause","main":"./dist/index.js","name":"global-agent","nyc":{"all":true,"exclude":["src/bin","src/queries/*.js"],"include":["src/**/*.js"],"instrument":false,"reporter":["html","text-summary"],"require":["@babel/register"],"silent":true,"sourceMap":false},"repository":{"type":"git","url":"git+https://github.com/gajus/global-agent.git"},"scripts":{"build":"rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist","create-readme":"gitdown ./.README/README.md --output-file ./README.md","dev":"NODE_ENV=development babel ./src --out-dir ./dist --copy-files --source-maps --watch","lint":"eslint ./src ./test && flow","test":"NODE_TLS_REJECT_UNAUTHORIZED=false NODE_ENV=test nyc ava --verbose --serial"},"version":"2.2.0","gitHead":"debc4e6379074a808ead584f6265d5f8605ff1ad","bugs":{"url":"https://github.com/gajus/global-agent/issues"},"homepage":"https://github.com/gajus/global-agent#readme","_id":"global-agent@2.2.0","_nodeVersion":"15.13.0","_npmVersion":"7.8.0","dist":{"integrity":"sha512-+20KpaW6DDLqhG7JDiJpD1JvNvb8ts+TNl7BPOYcURqCrXqnN1Vf+XVOrkKJAFPqfX+oEhsdzOj1hLWkBTdNJg==","shasum":"566331b0646e6bf79429a16877685c4a1fbf76dc","tarball":"http://registry-npm.ywwl.com/global-agent/download/global-agent-2.2.0.tgz","fileCount":73,"unpackedSize":125132,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgZpSBCRA9TVsSAnZWagAAK64P/jdKZQoAVobGYWExnrbs\nu23dvp6bfUl1+l68ydg3Y3P9zpfolHgc2Uf/s3nAfUKwz60lYXpzgp3bOnNQ\nxk6mwEPyMlChrUjjr9d4Hbmu0NPDrXNwk7PRsU8J570G1kDbpm97F+P9bUT8\npUkHQYyjiZzYW9K7jluh5Uwe2Rs+XBcM9FFlpo0Mrwf4Ke77wqVN3LlqsF/F\nxmC/9dubzmBNo6hWhhHQRHAeio4PzklxybHXe/kJgFmajOrGlsn6JV3bpDZV\nXRqbZ1vNB2rqgLySg7/INpn9nBSUbdSbI8gSI3vGz0x+l8q/Xd7+LdsQPcjh\nH4uqBPp6pcbQYG9K9lFdWzIEBnqPDBvA1EQk3aAd+OymV0ZiVoDTNaMDsuzI\nI2fH7o0QjwaIVD2rtDoGfa4UJn7oX1Lm4aH6QEPGJeE4RBXo4g5DLiss0SOa\nQmHQzcSUmDNkYmlUWnRRlIE4Dot88Vi1og6/mzv1TZIS+rBBX24hucJBmspg\nwvGFrOr3/TbSXXJQo4rWzpJDuMLZ1hKG9WBpHY17NuU8/85Y9Utro1mU2fTH\np6Rnt7edvAx2k7T3j94f54djTVgP1d7GQ7JjzwGf0wp5womug184XGrMeOht\nYz0+N7gV1Go4yEyl7PQqGK39Ubnh0QpbIP46tj96Sg1WbTtq/fwp/Xngodr/\ntTtK\r\n=FkX2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICxM5jA4o3q4XEsWMtQdAtqWSZ6rf3t/mTAZh00Hs92zAiEA06//As8wJjXzZAIy3C0+YzHpEnRfSNAQITJboUM6PL4="}],"size":30551,"noattachment":false,"key":"/global-agent/-/global-agent-2.2.0.tgz"},"_npmUser":{"name":"gajus","email":"gajus@gajus.com"},"directories":{},"maintainers":[{"name":"gajus","email":"gajus@gajus.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/global-agent_2.2.0_1617335425074_0.8983619499579389"},"_hasShrinkwrap":false,"readme":"# global-agent\n\n[![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/global-agent?style=flat-square)](https://gitspo.com/mentions/gajus/global-agent)\n[![Travis build status](http://img.shields.io/travis/gajus/global-agent/master.svg?style=flat-square)](https://travis-ci.org/gajus/global-agent)\n[![Coveralls](https://img.shields.io/coveralls/gajus/global-agent.svg?style=flat-square)](https://coveralls.io/github/gajus/global-agent)\n[![NPM version](http://img.shields.io/npm/v/global-agent.svg?style=flat-square)](https://www.npmjs.org/package/global-agent)\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)\n\nGlobal HTTP/HTTPS proxy configurable using environment variables.\n\n* [Usage](#usage)\n  * [Setup proxy using `global-agent/bootstrap`](#setup-proxy-using-global-agentbootstrap)\n  * [Setup proxy using `bootstrap` routine](#setup-proxy-using-bootstrap-routine)\n  * [Runtime configuration](#runtime-configuration)\n  * [Exclude URLs](#exclude-urls)\n  * [Enable logging](#enable-logging)\n* [API](#api)\n  * [`createGlobalProxyAgent`](#createglobalproxyagent)\n  * [Environment variables](#environment-variables)\n  * [`global.GLOBAL_AGENT`](#globalglobal_agent)\n* [Supported libraries](#supported-libraries)\n* [FAQ](#faq)\n  * [What is the reason `global-agent` overrides explicitly configured HTTP(S) agent?](#what-is-the-reason-global-agent-overrides-explicitly-configured-https-agent)\n  * [What is the reason `global-agent/bootstrap` does not use `HTTP_PROXY`?](#what-is-the-reason-global-agentbootstrap-does-not-use-http_proxy)\n  * [What is the difference from `global-tunnel` and `tunnel`?](#what-is-the-difference-from-global-tunnel-and-tunnel)\n\n## Usage\n\n### Setup proxy using `global-agent/bootstrap`\n\nTo configure HTTP proxy:\n\n1. Import `global-agent/bootstrap`.\n1. Export HTTP proxy address as `GLOBAL_AGENT_HTTP_PROXY` environment variable.\n\nCode:\n\n```js\nimport 'global-agent/bootstrap';\n\n// or:\n// import {bootstrap} from 'global-agent';\n// bootstrap();\n\n```\n\nBash:\n\n```bash\n$ export GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:8080\n\n```\n\nAlternatively, you can preload module using Node.js `--require, -r` configuration, e.g.\n\n```bash\n$ export GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:8080\n$ node -r 'global-agent/bootstrap' your-script.js\n\n```\n\n### Setup proxy using `bootstrap` routine\n\nInstead of importing a self-initialising script with side-effects as demonstrated in the [setup proxy using `global-agent/bootstrap`](#setup-proxy-using-global-agentbootstrap) documentation, you can import `bootstrap` routine and explicitly evaluate the bootstrap logic, e.g.\n\n```js\nimport {\n  bootstrap\n} from 'global-agent';\n\nbootstrap();\n\n```\n\nThis is useful if you need to conditionally bootstrap `global-agent`, e.g.\n\n```js\nimport {\n  bootstrap\n} from 'global-agent';\nimport globalTunnel from 'global-tunnel-ng';\n\nconst MAJOR_NODEJS_VERSION = parseInt(process.version.slice(1).split('.')[0], 10);\n\nif (MAJOR_NODEJS_VERSION >= 10) {\n  // `global-agent` works with Node.js v10 and above.\n  bootstrap();\n} else {\n  // `global-tunnel-ng` works only with Node.js v10 and below.\n  globalTunnel.initialize();\n}\n\n```\n\n### Setup proxy using `createGlobalProxyAgent`\n\nIf you do not want to use `global.GLOBAL_AGENT` variable, then you can use `createGlobalProxyAgent` to instantiate a controlled instance of `global-agent`, e.g.\n\n```js\nimport {\n  createGlobalProxyAgent\n} from 'global-agent';\n\nconst globalProxyAgent = createGlobalProxyAgent();\n\n```\n\nUnlike `bootstrap` routine, `createGlobalProxyAgent` factory does not create `global.GLOBAL_AGENT` variable and does not guard against multiple initializations of `global-agent`. The result object of `createGlobalProxyAgent` is equivalent to `global.GLOBAL_AGENT`.\n\n### Runtime configuration\n\n`global-agent/bootstrap` script copies `process.env.GLOBAL_AGENT_HTTP_PROXY` value to `global.GLOBAL_AGENT.HTTP_PROXY` and continues to use the latter variable.\n\nYou can override the `global.GLOBAL_AGENT.HTTP_PROXY` value at runtime to change proxy behaviour, e.g.\n\n```js\nhttp.get('http://127.0.0.1:8000');\n\nglobal.GLOBAL_AGENT.HTTP_PROXY = 'http://127.0.0.1:8001';\n\nhttp.get('http://127.0.0.1:8000');\n\nglobal.GLOBAL_AGENT.HTTP_PROXY = 'http://127.0.0.1:8002';\n\n```\n\nThe first HTTP request is going to use http://127.0.0.1:8001 proxy and the secord request is going to use http://127.0.0.1:8002.\n\nAll `global-agent` configuration is available under `global.GLOBAL_AGENT` namespace.\n\n### Exclude URLs\n\nThe `GLOBAL_AGENT_NO_PROXY` environment variable specifies a pattern of URLs that should be excluded from proxying. `GLOBAL_AGENT_NO_PROXY` value is a comma-separated list of domain names. Asterisks can be used as wildcards, e.g.\n\n```bash\nexport GLOBAL_AGENT_NO_PROXY='*.foo.com,baz.com'\n\n```\n\nsays to contact all machines with the 'foo.com' TLD and 'baz.com' domains directly.\n\n### Separate proxy for HTTPS\n\nThe environment variable `GLOBAL_AGENT_HTTPS_PROXY` can be set to specify a separate proxy for HTTPS requests. When this variable is not set `GLOBAL_AGENT_HTTP_PROXY` is used for both HTTP and HTTPS requests.\n\n### Enable logging\n\n`global-agent` is using [`roarr`](https://www.npmjs.com/package/roarr) logger to log HTTP requests and response (HTTP status code and headers), e.g.\n\n```json\n{\"context\":{\"program\":\"global-agent\",\"namespace\":\"Agent\",\"logLevel\":10,\"destination\":\"http://gajus.com\",\"proxy\":\"http://127.0.0.1:8076\"},\"message\":\"proxying request\",\"sequence\":1,\"time\":1556269669663,\"version\":\"1.0.0\"}\n{\"context\":{\"program\":\"global-agent\",\"namespace\":\"Agent\",\"logLevel\":10,\"headers\":{\"content-type\":\"text/plain\",\"content-length\":\"2\",\"date\":\"Fri, 26 Apr 2019 12:07:50 GMT\",\"connection\":\"close\"},\"requestId\":6,\"statusCode\":200},\"message\":\"proxying response\",\"sequence\":2,\"time\":1557133856955,\"version\":\"1.0.0\"}\n\n```\n\nExport `ROARR_LOG=true` environment variable to enable log printing to stdout.\n\nUse [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print the logs.\n\n## API\n\n### `createGlobalProxyAgent`\n\n```js\n/**\n * @property environmentVariableNamespace Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables. (Default: `GLOBAL_AGENT_`)\n * @property forceGlobalAgent Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent. (Default: `true`)\n * @property socketConnectionTimeout Destroys socket if connection is not established within the timeout. (Default: `60000`)\n */\ntype ProxyAgentConfigurationInputType = {|\n  +environmentVariableNamespace?: string,\n  +forceGlobalAgent?: boolean,\n  +socketConnectionTimeout?: number,\n|};\n\n(configurationInput: ProxyAgentConfigurationInputType) => ProxyAgentConfigurationType;\n\n```\n\n### Environment variables\n\n|Name|Description|Default|\n|---|---|---|\n|`GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE`|Defines namespace of `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables.|`GLOBAL_AGENT_`|\n|`GLOBAL_AGENT_FORCE_GLOBAL_AGENT`|Forces to use `global-agent` HTTP(S) agent even when request was explicitly constructed with another agent.|`true`|\n|`GLOBAL_AGENT_SOCKET_CONNECTION_TIMEOUT`|Destroys socket if connection is not established within the timeout.|`60000`|\n|`${NAMESPACE}_HTTP_PROXY`|Sets the initial proxy controller HTTP_PROXY value.|N/A|\n|`${NAMESPACE}_HTTPS_PROXY`|Sets the initial proxy controller HTTPS_PROXY value.|N/A|\n|`${NAMESPACE}_NO_PROXY`|Sets the initial proxy controller NO_PROXY value.|N/A|\n\n### `global.GLOBAL_AGENT`\n\n`global.GLOBAL_AGENT` is initialized by `bootstrap` routine.\n\n`global.GLOBAL_AGENT` has the following properties:\n\n|Name|Description|Configurable|\n|---|---|---|\n|`HTTP_PROXY`|Yes|Sets HTTP proxy to use.|\n|`HTTPS_PROXY`|Yes|Sets a distinct proxy to use for HTTPS requests.|\n|`NO_PROXY`|Yes|Specifies a pattern of URLs that should be excluded from proxying. See [Exclude URLs](#exclude-urls).|\n\n## Supported libraries\n\n`global-agent` works with all libraries that internally use [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback).\n\n`global-agent` has been tested to work with:\n\n* [`got`](https://www.npmjs.com/package/got)\n* [`axios`](https://www.npmjs.com/package/axios)\n* [`request`](https://www.npmjs.com/package/axios)\n\n## FAQ\n\n### What is the reason `global-agent` overrides explicitly configured HTTP(S) agent?\n\nBy default, `global-agent` overrides [`agent` property](https://nodejs.org/api/http.html#http_http_request_options_callback) of any HTTP request, even if `agent` property was explicitly set when constructing a HTTP request. This behaviour allows to intercept requests of libraries that use a custom instance of an agent per default (e.g. Stripe SDK [uses an `http(s).globalAgent` instance pre-configured with `keepAlive: true`](https://github.com/stripe/stripe-node/blob/e542902dd8fbe591fe3c3ce07a7e89d1d60e4cf7/lib/StripeResource.js#L11-L12)).\n\nThis behaviour can be disabled with `GLOBAL_AGENT_FORCE_GLOBAL_AGENT=false` environment variable. When disabled, then `global-agent` will only set `agent` property when it is not already defined or if `agent` is an instance of `http(s).globalAgent`.\n\n### What is the reason `global-agent/bootstrap` does not use `HTTP_PROXY`?\n\nSome libraries (e.g. [`request`](https://npmjs.org/package/request)) change their behaviour when `HTTP_PROXY` environment variable is present. Using a namespaced environment variable prevents conflicting library behaviour.\n\nYou can override this behaviour by configuring `GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE` variable, e.g.\n\n```bash\n$ export GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE=\n\n```\n\nNow script initialized using `global-agent/bootstrap` will use `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables.\n\n### What is the difference from `global-tunnel` and `tunnel`?\n\n[`global-tunnel`](https://github.com/salesforce/global-tunnel) (including [`global-tunnel-ng`](https://github.com/np-maintain/global-tunnel) and [`tunnel`](https://npmjs.com/package/tunnel)) are designed to support legacy Node.js versions. They use various [workarounds](https://github.com/koichik/node-tunnel/blob/5fb2fb424788597146b7be6729006cad1cf9e9a8/lib/tunnel.js#L134-L144) and rely on [monkey-patching `http.request`, `http.get`, `https.request` and `https.get` methods](https://github.com/np-maintain/global-tunnel/blob/51413dcf0534252b5049ec213105c7063ccc6367/index.js#L302-L338).\n\nIn contrast, `global-agent` supports Node.js v10 and above, and does not implements workarounds for the older Node.js versions.\n","publish_time":1617335425217,"_cnpm_publish_time":1617335425217,"dist-tags":{"latest":"4.1.6"}}