@fastify/reply-from
Advanced tools
Comparing version 8.3.1 to 8.4.0
@@ -40,3 +40,4 @@ 'use strict' | ||
base, | ||
undici: opts.undici | ||
undici: opts.undici, | ||
globalAgent: opts.globalAgent | ||
}) | ||
@@ -244,3 +245,5 @@ if (requestBuilt instanceof Error) { | ||
function isFastifyMultipartRegistered (fastify) { | ||
return fastify.hasContentTypeParser('multipart') && fastify.hasRequestDecorator('multipart') | ||
// TODO: remove fastify.hasContentTypeParser('multipart') in next major | ||
// It is used to be compatible with @fastify/multipart@<=7.3.0 | ||
return (fastify.hasContentTypeParser('multipart') || fastify.hasContentTypeParser('multipart/form-data')) && fastify.hasRequestDecorator('multipart') | ||
} | ||
@@ -247,0 +250,0 @@ |
@@ -44,2 +44,3 @@ 'use strict' | ||
const undiciOpts = opts.undici || {} | ||
const globalAgent = opts.globalAgent | ||
let http2Client | ||
@@ -55,3 +56,3 @@ let undiciAgent | ||
} | ||
} else { | ||
} else if (!globalAgent) { | ||
agents = httpOpts.agents || { | ||
@@ -61,2 +62,7 @@ 'http:': new http.Agent(httpOpts.agentOptions), | ||
} | ||
} else { | ||
agents = { | ||
'http:': http.globalAgent, | ||
'https:': https.globalAgent | ||
} | ||
} | ||
@@ -74,4 +80,6 @@ | ||
undiciInstance = opts.undici | ||
} else if (!globalAgent) { | ||
undiciAgent = new undici.Agent(getUndiciOptions(opts.undici)) | ||
} else { | ||
undiciAgent = new undici.Agent(getUndiciOptions(opts.undici)) | ||
undiciAgent = undici.getGlobalDispatcher() | ||
} | ||
@@ -84,2 +92,6 @@ return { request: handleUndici, close, retryOnError: 'UND_ERR_SOCKET' } | ||
function close () { | ||
if (globalAgent) { | ||
return | ||
} | ||
if (hasUndiciOptions) { | ||
@@ -86,0 +98,0 @@ undiciAgent && undiciAgent.destroy() |
{ | ||
"name": "@fastify/reply-from", | ||
"version": "8.3.1", | ||
"version": "8.4.0", | ||
"description": "forward your HTTP request to another server, for fastify", | ||
@@ -31,4 +31,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@fastify/formbody": "^7.0.1", | ||
"@fastify/multipart": "^7.1.0", | ||
"@fastify/formbody": "^7.4.0", | ||
"@fastify/multipart": "^7.4.0", | ||
"@fastify/pre-commit": "^2.0.2", | ||
@@ -50,3 +50,3 @@ "@sinonjs/fake-timers": "^10.0.0", | ||
"tap": "^16.2.0", | ||
"tsd": "^0.24.1" | ||
"tsd": "^0.25.0" | ||
}, | ||
@@ -53,0 +53,0 @@ "dependencies": { |
# @fastify/reply-from | ||
[![CI](https://github.com/fastify/reply-fro/workflows/CI/badge.svg)](https://github.com/fastify/reply-fro/actions/workflows/ci.yml) | ||
[![CI](https://github.com/fastify/fastify-reply-from/workflows/CI/badge.svg)](https://github.com/fastify/fastify-reply-from/actions/workflows/ci.yml) | ||
[![NPM version](https://img.shields.io/npm/v/@fastify/reply-from.svg?style=flat)](https://www.npmjs.com/package/@fastify/reply-from) | ||
@@ -169,3 +169,3 @@ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) | ||
}, | ||
requestTimeout: { // HTTP/2 request options, pass in any options from https://nodejs.org/api/http2.html#http2_clienthttp2session_request_headers_options | ||
requestOptions: { // HTTP/2 request options, pass in any options from https://nodejs.org/api/http2.html#clienthttp2sessionrequestheaders-options | ||
endStream: true | ||
@@ -220,2 +220,30 @@ } | ||
#### `globalAgent` | ||
Enables the possibility to explictly opt-in for global agents. | ||
Usage for undici global agent: | ||
```js | ||
import { setGlobalDispatcher, ProxyAgent } from 'undici' | ||
const proxyAgent = new ProxyAgent('my.proxy.server') | ||
setGlobalDispatcher(proxyAgent) | ||
fastify.register(FastifyReplyFrom, { | ||
base: 'http://localhost:3001/', | ||
globalAgent: true | ||
}) | ||
``` | ||
Usage for http/https global agent: | ||
```js | ||
fastify.register(FastifyReplyFrom, { | ||
base: 'http://localhost:3001/', | ||
// http and https is allowed to use http.globalAgent or https.globalAgent | ||
globalAgent: true, | ||
http: { | ||
} | ||
}) | ||
``` | ||
--- | ||
@@ -222,0 +250,0 @@ |
@@ -98,2 +98,3 @@ /// <reference types="node" /> | ||
disableRequestLogging?: boolean; | ||
globalAgent?: boolean; | ||
} | ||
@@ -100,0 +101,0 @@ |
@@ -48,2 +48,3 @@ import replyFrom, { FastifyReplyFromOptions } from ".."; | ||
disableRequestLogging: false, | ||
globalAgent: false, | ||
}; | ||
@@ -50,0 +51,0 @@ tap.autoend(false); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164220
98
4862
374
11
66