{"author":{"name":"Gajus Kuizinas","email":"gajus@gajus.com","url":"http://gajus.com"},"ava":{"files":["test/**/*"],"helpers":["test/helpers/**/*"],"require":["@babel/register"],"sources":["src/**/*"]},"dependencies":{"boolean":"^1.0.0","core-js":"^3.2.1","es6-error":"^4.1.1","matcher":"^2.0.0","roarr":"^2.14.1","semver":"^6.3.0","serialize-error":"^4.1.0"},"description":"Global HTTP/HTTPS proxy configurable using environment variables.","devDependencies":{"@babel/cli":"^7.5.5","@babel/core":"^7.5.5","@babel/node":"^7.5.5","@babel/plugin-transform-flow-strip-types":"^7.4.4","@babel/preset-env":"^7.5.5","@babel/register":"^7.5.5","anyproxy":"^4.1.0","ava":"^2.2.0","axios":"^0.19.0","babel-plugin-istanbul":"^5.2.0","babel-plugin-transform-export-default-name":"^2.0.4","coveralls":"^3.0.6","eslint":"^6.1.0","eslint-config-canonical":"^17.3.4","flow-bin":"^0.105.2","flow-copy-source":"^2.0.7","get-port":"^5.0.0","got":"^9.6.0","husky":"^3.0.3","nyc":"^14.1.1","pem":"^1.14.2","request":"^2.88.0","semantic-release":"^15.13.21","sinon":"^7.4.1"},"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_ENV=test nyc ava --verbose --serial"},"version":"2.0.2","gitHead":"1c9a5a7fff9f73545942bb4e3494c11cb5665dcb","bugs":{"url":"https://github.com/gajus/global-agent/issues"},"homepage":"https://github.com/gajus/global-agent#readme","_id":"global-agent@2.0.2","_nodeVersion":"12.8.1","_npmVersion":"6.10.3","dist":{"integrity":"sha512-mQLICTW+QGJPuEI8WvEjdyPCcEnx5OqmJH2ADGtv9NknBfUsTnUsV9NeKfrjkwauT2zrSGQqDrS49f86kvnXoA==","shasum":"4c09f89dc3aef78e9304bcd5b42e8d4a5048daab","tarball":"http://registry-npm.ywwl.com/global-agent/download/global-agent-2.0.2.tgz","fileCount":73,"unpackedSize":107595,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdVaA1CRA9TVsSAnZWagAAxs4P+gPyrJP5y7VwLBRrxbew\nF+7X57P4uLLEHxlLbtpUxMxV0nvFkoLhfpqIEIqloNBBJeUx2fX0jqy/lP6T\n1Nv7gYkW2UycdcOUsv9cengJUsGdVoydYvWUo3cZbRf/qwdbEwZ6YSIyvzhh\nnIzYmTNp/GOP6UveDdlDJCPBkBWutGMQFZJpURj2/Cec2r4PEEvPLsNVUihs\nNaLY+y09X5C3GTru7zqGvRoddR/pimg50ZUjG0YzFo57ZemSf6zu4GRUP/bE\nRz9wUVhYnUSj5gJH96fucsBx5S4zgI+nGMGHL49pog0/CrwfPAgFVbrAyT7I\nwn1KvDne5MDjRF/WwajnhbpgpaiUVoQH82xvn/shkTDJ4YbSyJcuSjma+FMs\nZNN/JlmQ+hHrqOr5/CciPrs4dZf3yQC09sGJHPVhF0uknslCoShJxdVlHdBL\npwgTeJcTxr3oICjTBqdGR/7pgLQ3twRWycruOL6rVDV2iULQEx0Dz7ddeNpo\nuKzyUiaQvXA8ZkTkg+XNGKTv85TuirsM52ugameSrSM2JZfDbX4PCI5CnJKJ\n0Lj6AER2F6EhnUGaDQp1jDW08zfOEhb6XPCvD5u9243M4Wdxt7eQKe6mbYhP\nnwAwJYrqGZ5plyYByGGPRjFCLMXxKKaHjFzu0n0+2ru2pdWyoIt6tg+9r0Y6\ncn1u\r\n=7g64\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDFI8aGmhdoT9HPhOAaQ134Y7rFAtoW8m1uEZBkuY+TFwIhAIA8QaA99JCQXyjXTRh5l8IMvdtMqybUvL4tUoNp0Zqa"}],"size":26326,"noattachment":false,"key":"/global-agent/-/global-agent-2.0.2.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_2.0.2_1565892660664_0.2078668125963019"},"_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":1565892660822,"_cnpm_publish_time":1565892660822,"dist-tags":{"latest":"4.1.6"}}