{"tsd":{"directory":"test"},"bugs":{"url":"https://github.com/fastify/fastify-reply-from/issues"},"dist":{"shasum":"4147a5a71b65ea1e64f636f849a3ce17c8c9ec9d","tarball":"https://registry.npmjs.org/fastify-reply-from/-/fastify-reply-from-3.0.0.tgz","fileCount":51,"integrity":"sha512-CUqj5MrZjG/cCxwB6o19LaAQmTCysyOpWkUyk2Znh+26Fh0wKL9tr4icfMwxI0PKzgWIjxxd2Dr7Avyn8hoMWg==","signatures":[{"sig":"MEUCIQDwvMhon453f4+Z6PSE1OPHyNj1Jc7JWNs7ubKhhT1RvQIgXRkPb7FgmfCRUzWct6IJiSZns6JwWsvvDPqU2D8vWsg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":75793,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeuQ93CRA9TVsSAnZWagAA6zsQAJyZP3+KAkBIWFOgTsF5\nb5V1GNgo+Dd13mx2IDRNfpRSt7E7GwZoNvcLuDzkNY0ZnDy7lZ4ZBhnLLJNh\nuQBX7q6u+qz40KNvl1zAO1/HQMAO+1cOnq2jBevutTlBSNT5KLR8LNdNC5gy\ne017cH3w61wv41r6NDn1ZflneTO+Q4L5azL1X+HwAx7O72DTGOQk0zEwpDUV\na+THBDn53INgjeNrW/Da1Shg8uG0CcUy47ZMpfBJLlEvnCYiECP1UVBrs7R1\nTMEYi/EZW2aNY2tni9hGevC8tuTMsoRV71Z6pyacuK+Eu1Nd4YxoSdRY5DvZ\n1tfe8lmtB9Fd39MjuR7779IAixkfPjim88HSAy2CUaZi2GahbC4NouPOow9K\nXhwd8ByX+CkxheYBWkFepvAyB+fWlxNi8EWW/Yw+eBmge3vapaRg2xUeYy5Y\nlseJWWjQtOp1Jp1rliFUDz3cPIUEQUX9PoQWOcR7orB6EZV+RtYdoURIRg38\nwCmOfYq00GvaexegcxYN0ZQc6Rqb8dE+4eeBxOcb5v9hGVqwuGJ3GzNyiZ4E\nP0ZDZNbJM5qXtgoUGXY2/ycKpzMDk/gg3YDHR4NbBWXapynrMMub/mk1T+1A\nekETCQ4lACWAhfpCcU1JDP7+dvDj+6dPeA2ew10AWrsthznpK9rrOPabKrHE\ntr9T\r\n=Qjgb\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","name":"fastify-reply-from","types":"index.d.ts","author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"readme":"# fastify-reply-from\n\n![CI](https://github.com/fastify/fastify-reply-from/workflows/CI/badge.svg)\n[![NPM version](https://img.shields.io/npm/v/fastify-reply-from.svg?style=flat)](https://www.npmjs.com/package/fastify-reply-fromm)\n\nfastify plugin to forward the current http request to another server.\nHTTP2 to HTTP is supported too.\n\n## Install\n\n```\nnpm i fastify-reply-from\n```\n\n## Usage\n\nThe following example set up two fastify servers and forward the request\nfrom one to the other.\n\n```js\n'use strict'\n\nconst Fastify = require('fastify')\n\nconst target = Fastify({\n  logger: true\n})\n\ntarget.get('/', (request, reply) => {\n  reply.send('hello world')\n})\n\nconst proxy = Fastify({\n  logger: true\n})\n\nproxy.register(require('fastify-reply-from'), {\n  base: 'http://localhost:3001/'\n})\n\nproxy.get('/', (request, reply) => {\n  reply.from('/')\n})\n\ntarget.listen(3001, (err) => {\n  if (err) {\n    throw err\n  }\n\n  proxy.listen(3000, (err) => {\n    if (err) {\n      throw err\n    }\n  })\n})\n```\n\n## API\n\n### Plugin options\n\n#### `base`\n\nSet the base URL for all the forwarded requests. Will be required if `http2` is set to `true`\nNote that _every path will be discarded_.\n\n#### `http`\nBy default, Node's [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback)\nwill be used if you don't enable [`http2`](#http2) or [`undici`](#undici). To customize the `request`,\nyou can pass in [`agentOptions`](https://nodejs.org/api/http.html#http_new_agent_options) and\n[`requestOptions`](https://nodejs.org/api/http.html#http_http_request_options_callback). To illustrate:\n\n```js\nproxy.register(require('fastify-reply-from'), {\n  base: 'http://localhost:3001/',\n  http: {\n    agentOptions: { // pass in any options from https://nodejs.org/api/http.html#http_new_agent_options\n      keepAliveMsecs: 10 * 60 * 1000\n    },\n    requestOptions: { // pass in any options from https://nodejs.org/api/http.html#http_http_request_options_callback\n      timeout: 5000 // timeout in msecs, defaults to 10000 (10 seconds)\n    }\n  }\n})\n```\n\n#### `http2`\nYou can either set `http2` to `true` or set the settings object to connect to a HTTP/2 server.\nThe `http2` settings object has the shape of:\n\n```js\nproxy.register(require('fastify-reply-from'), {\n  base: 'http://localhost:3001/',\n  http2: {\n    sessionTimeout: 10000, // HTTP/2 session timeout in msecs, defaults to 60000 (1 minute)\n    requestTimeout: 5000, // HTTP/2 request timeout in msecs, defaults to 10000 (10 seconds)\n    sessionOptions: { // HTTP/2 session connect options, pass in any options from https://nodejs.org/api/http2.html#http2_http2_connect_authority_options_listener\n      rejectUnauthorized: true\n    },\n    requestTimeout: { // HTTP/2 request options, pass in any options from https://nodejs.org/api/http2.html#http2_clienthttp2session_request_headers_options\n      endStream: true\n    }\n  }\n})\n```\n\n#### `undici`\nSet to `true` to use [undici](https://github.com/mcollina/undici)\ninstead of `require('http')`. Enabling this flag should guarantee\n20-50% more throughput.\n\nThis flag could controls the settings of the undici client, like so:\n\n```js\nproxy.register(require('fastify-reply-from'), {\n  base: 'http://localhost:3001/',\n  undici: {\n    connections: 100,\n    pipelining: 10\n  }\n})\n```\n\n#### `cacheURLs`\n\nThe number of parsed URLs that will be cached. Default: `100`.\n\n#### `keepAliveMsecs`\n\n**(Deprecated)** Defaults to 1 minute (`60000`), passed down to [`http.Agent`][http-agent] and\n[`https.Agent`][https-agent] instances. Prefer to use [`http.agentOptions`](#http) instead.\n\n#### `maxSockets`\n\n**(Deprecated)** Defaults to `2048` sockets, passed down to [`http.Agent`][http-agent] and\n[`https.Agent`][https-agent] instances. Prefer to use [`http.agentOptions`](#http) instead.\n\n#### `maxFreeSockets`\n\n**(Deprecated)** Defaults to `2048` free sockets, passed down to [`http.Agent`][http-agent] and\n[`https.Agent`][https-agent] instances. Prefer to use [`http.agentOptions`](#http) instead.\n\n#### `rejectUnauthorized`\n\n**(Deprecated)** Defaults to `false`, passed down to [`https.Agent`][https-agent] instances.\nThis needs to be set to `false` to reply from https servers with\nself-signed certificates. Prefer to use [`http.requestOptions`](#http) or\n[`http2.sessionOptions`](#http2) instead.\n\n#### `sessionTimeout`\n\n**(Deprecated)** The timeout value after which the HTTP2 client session is destroyed if there\nis no activity. Defaults to 1 minute (`60000`). Prefer to use [`http2.sessionTimeout`](#http2) instead.\n\n---\n\n### `reply.from(source, [opts])`\n\nThe plugin decores the\n[`Reply`](https://github.com/fastify/fastify/blob/master/docs/Reply.md)\ninstance with a `from` method, which will reply to the original request\n__from the desired source__. The options allows to override any part of\nthe request or response being sent or received to/from the source.\n\n#### `onResponse(request, reply, res)`\n\nCalled when an http response is received from the source.\nThe default behavior is `reply.send(res)`, which will be disabled if the\noption is specified.\n\n#### `rewriteHeaders(headers)`\n\nCalled to rewrite the headers of the response, before them being copied\nover to the outer response.\nIt must return the new headers object.\n\n#### `rewriteRequestHeaders(originalReq, headers)`\n\nCalled to rewrite the headers of the request, before them being sent to the other server.\nIt must return the new headers object.\n\n#### `queryString`\n\nReplaces the original querystring of the request with what is specified.\nThis will get passed to\n[`querystring.stringify`](https://nodejs.org/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options).\n\n#### `body`\n\nReplaces the original request body with what is specified. Unless\n[`contentType`][contentType] is specified, the content will be passed\nthrough `JSON.stringify()`.\nSetting this option will not verify if the http method allows for a body.\n\n#### `contentType`\n\nOverride the `'Content-Type'` header of the forwarded request, if we are\nalready overriding the [`body`][body].\n\n### HTTP & HTTP2 timeouts\n\nThis library has:\n- `timeout` for `http` set by default. The default value is 10 seconds (`10000`).\n- `requestTimeout` & `sessionTimeout` for `http2` set by default.\n  - The default value for `requestTimeout` is 10 seconds (`10000`).\n  - The default value for `sessionTimeout` is 60 seconds (`60000`).\n\nWhen a timeout happens, [`504 Gateway Timeout`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504)\nwill be returned to the client.\n\n## TODO\n\n* [ ] support overriding the body with a stream\n* [ ] forward the request id to the other peer might require some\n      refacotring because we have to make the `req.id` unique\n      (see [hyperid](http://npm.im/hyperid)).\n* [ ] Support origin HTTP2 push\n* [x] benchmarks\n\n## License\n\nMIT\n\n[http-agent]: https://nodejs.org/api/http.html#http_new_agent_options\n[https-agent]: https://nodejs.org/api/https.html#https_class_https_agent\n","engines":{"node":">=8.0.0"},"gitHead":"236199f836f778b5d3af9b29c605cf7f7eba19f0","license":"MIT","scripts":{"test":"standard | snazzy && tap test/*.js && npm run typescript","coverage":"tap -j8 test/*.js --cov","typescript":"tsd"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"homepage":"https://github.com/fastify/fastify-reply-from#readme","keywords":["fastify","http","forward","proxy"],"repository":{"url":"git+https://github.com/fastify/fastify-reply-from.git","type":"git"},"_npmVersion":"6.14.5","description":"forward your HTTP request to another server, for fastify","directories":{},"maintainers":[{"name":"allevo","email":"tomallevi@gmail.com"},{"name":"cemremengu","email":"cemremengu@gmail.com"},{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"eomm","email":"behemoth89@gmail.com"},{"name":"ethan_arrowood","email":"ethan.arrowood@gmail.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"starptech","email":"deusdustin@gmail.com"}],"_nodeVersion":"12.16.1","dependencies":{"pump":"^3.0.0","semver":"^7.2.1","undici":"^0.5.0","tiny-lru":"^7.0.0","end-of-stream":"^1.4.1","fastify-plugin":"^2.0.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"got":"^11.1.3","tap":"^14.10.7","tsd":"^0.11.0","nock":"^12.0.3","h2url":"^0.2.0","snazzy":"^8.0.0","fastify":"^3.0.0-rc.1","msgpack5":"^4.2.1","standard":"^14.3.3","pre-commit":"^1.2.2","proxyquire":"^2.1.0","simple-get":"^3.0.3","typescript":"^3.8.3","@types/node":"^13.13.5"},"_npmOperationalInternal":{"tmp":"tmp/fastify-reply-from_3.0.0_1589186423297_0.11922332047454964","host":"s3://npm-registry-packages"},"_id":"fastify-reply-from@3.0.0","version":"3.0.0"}