{"tsd":{"directory":"test"},"bugs":{"url":"https://github.com/fastify/fastify-reply-from/issues"},"dist":{"shasum":"65c884ba55888285ec0b964e57875e7bf4ff10cc","tarball":"https://registry.npmjs.org/fastify-reply-from/-/fastify-reply-from-3.1.1.tgz","fileCount":55,"integrity":"sha512-kNCi286Oe2+B5DW3pr1uSEn2moYMJnU4VwGiieY3wUNk9buF7GZrW+dsjFOJd+CrZpgGVpJMnFiLsizVxBOyFQ==","signatures":[{"sig":"MEUCIQCAWBCxq9Y8XAVmT6VTrwnJHnXnNI1rDql98+YXctLFjAIgByqnZoXnvoxTWb3Zq4lw1PxZHO1hvO27pL8SGk2ULsc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":81446,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe/zv5CRA9TVsSAnZWagAA6AoP/RuSmPQwE4knwKG3PLRk\nQjaBarpUD2+ThYXstsQs9AvRITLSC6fuCxmtCV1QTsDaAiqvhf4PLhD23wrg\nLpcdtwh5oumDnIy0AuSUvcVwe8xtoTxkQd74T1D62v9Pc7R95/Twg9Ddj+TS\n2ei6cBjVKGkPgA0ohAevPpkjTDGU+R000YWGzq0uduv9yHnzi3R7+et6pO/P\nTnh/NZKMbpbqvaqTuLxmRpdUm0EK8bWSK39vTy+/2IhiB5dPaXpOOhort+v6\nyHLRUMeU8xlcbIxrNQXEeCORLHo2uztnPgGO0lepQaco7UEAShGPR/SnCov7\n2m3XREPl62erNCLfwbphj6mYeSa2ltpu0XXokHKUimuwn+I7t0bda92JkBv9\n2EhPoD+9JbW3iLdY3XgvwLPsmzj2iCYifauSbZUvzkdl7nOiAG5WlTuHnN8T\nWVpEJAIPzBDllePjom7utZsXQBYziEaesLCh3MlhY0MZR2yqudpT7eHP9JFL\n7KavBMW1igymf6oVjqHLYkzKvr4ko+5jQj0/MIG9cEiUuB38cLD8KX0brkr5\n95Epj1fofx7UWKLa3EvvCwepqHkeVjs+LVVI5ckJZEQtbi5erCMv9NP6uEER\njySP4ihkvOC3JFATTss+GoklIL5xE3YA3ko/YLj8DqJIekXSVEUznVswn9dG\nYuW8\r\n=WtER\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\nCustom URL protocols `unix+http:` and `unix+https:` can be used to forward requests to a unix\nsocket server by using `querystring.escape(socketPath)` as the hostname.  This is not supported\nfor http2 nor unidici.  To illustrate:\n\n```js\nconst socketPath = require('querystring').escape('/run/http-daemon.socket')\nproxxy.register(require('fastify-reply-from'), {\n  base: 'unix+http://${socketPath}/'\n});\n```\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":"baa0263414751d3f5a8da005d62de3cd894ea112","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.18.1","dependencies":{"pump":"^3.0.0","semver":"^7.2.1","undici":"^1.0.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.12.0","nock":"^13.0.0","h2url":"^0.2.0","snazzy":"^8.0.0","fastify":"^3.0.0-rc.5","msgpack5":"^4.2.1","standard":"^14.3.3","pre-commit":"^1.2.2","proxyquire":"^2.1.3","simple-get":"^4.0.0","typescript":"^3.8.3","@types/node":"^14.0.4"},"_npmOperationalInternal":{"tmp":"tmp/fastify-reply-from_3.1.1_1593785337354_0.8395772520563769","host":"s3://npm-registry-packages"},"_id":"fastify-reply-from@3.1.1","version":"3.1.1"}