{"author":{"name":"Gajus Kuizinas","email":"gajus@gajus.com","url":"http://gajus.com"},"ava":{"require":["@babel/register"]},"dependencies":{"core-js":"^3.0.1","es6-error":"^4.1.1","matcher":"^2.0.0","roarr":"^2.13.0","semver":"^6.0.0","serialize-error":"^4.1.0"},"description":"Global HTTP/HTTPS proxy configurable using environment variables.","devDependencies":{"@babel/cli":"^7.4.4","@babel/core":"^7.4.4","@babel/node":"^7.2.2","@babel/plugin-transform-flow-strip-types":"^7.4.4","@babel/preset-env":"^7.4.4","@babel/register":"^7.4.4","anyproxy":"^4.1.0","ava":"^1.4.1","axios":"^0.18.0","babel-plugin-istanbul":"^5.1.4","babel-plugin-transform-export-default-name":"^2.0.4","coveralls":"^3.0.3","eslint":"^5.16.0","eslint-config-canonical":"^17.0.1","flow-bin":"^0.98.0","flow-copy-source":"^2.0.4","get-port":"^5.0.0","got":"^9.6.0","husky":"^2.2.0","nyc":"^14.1.0","pem":"^1.14.2","request":"^2.88.0","semantic-release":"^15.13.3","sinon":"^7.3.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","lint":"eslint ./src ./test && flow","test":"NODE_ENV=test nyc ava --verbose --serial"},"version":"1.7.1","gitHead":"5f38e52776f29101f1c279f756c3fc27bd7cd693","bugs":{"url":"https://github.com/gajus/global-agent/issues"},"homepage":"https://github.com/gajus/global-agent#readme","_id":"global-agent@1.7.1","_nodeVersion":"12.2.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-ceppEkOpS6lPjvRw7DDkwXWkMpw37rDv2gChQ9wWWfOvj1QZnyuXbGBBGyig6i6Hs3l+B3QrhxiQcsxiwWFoAw==","shasum":"985d1c00607c1acb96677119e282cf0485a8d160","tarball":"http://registry-npm.ywwl.com/global-agent/download/global-agent-1.7.1.tgz","fileCount":61,"unpackedSize":76115,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc1orkCRA9TVsSAnZWagAAyFAQAIY1r7jjvhRtOeByAkIE\np1oPtTl9yCy9RxfUL07cq/aNTaAtEI9jjZNtmVUEPekp4f3XdMZRq7vFBx/Q\n0Po7Szn5cqs5u22y6oIBfjPdqEWLN4h59tj0oEMBI5unYVCpUxWRGYmK2lvv\nffH3eKW0/HmuzJUJnuPQloTPp+RFxEi27cOwkt/3ynosFGS9rQQB2mGEmkBs\n30brfr9UktiD3t0WNA1MIvQgT0CNcZCgyHZVwV4foNTN55s+RCo+RoQUMZ2S\nXTkT2uuw4oFzhxSIHXsSyuY6x3OB6kiawFjFCVg3j9KxLE3MYngZ9lGfDbhw\nq+8QOsGsZIBQ8Sb/niAfRlv4Hqvo39muS1Kqc2dcMTwqkYQhJ5UPHjb5VLrK\n7Uwoyps1LiPI9SZqjw8m0eLeBib49cyg/fj3U95pUUI+NexrHpIj6R5xqlW0\n/+n/mgtzWCHr8kTsVqxQqDFxQhHy72g4Y34rCDTYpyqy7yMvzJMLhUaNRVO6\n/faPiwolDtpHeuUZft7aWcWZZlIIjt+VElrktCasvuuzuWa1MKTUfb2ClRsG\nLLZf8635Af3ykgmzNsNYypUQOmpOBviSxKxhzB4T6VSjoxPXY71vQanD7WIV\nfy/6x0wP2eoaPlTdBH/RIYt/AKowgPkUizezWaMafpIFjP3+CgqLR6fMhY5D\n+PGx\r\n=QYYs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE2svdPVRdeiH5+AkB+spwQmBM6n4MnIf6kxTbXNKixzAiEA6j/9PBeJ/Qi+7Yx1K/P2lJlELJM4jaxQqh34dg9UDVw="}],"size":18167,"noattachment":false,"key":"/global-agent/-/global-agent-1.7.1.tgz"},"maintainers":[{"name":"gajus","email":"gajus@gajus.com"}],"_npmUser":{"name":"gajus","email":"gajus@gajus.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/global-agent_1.7.1_1557564131773_0.22660501703846236"},"_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":1557564131907,"_cnpm_publish_time":1557564131907,"dist-tags":{"latest":"4.1.6"}}