diff --git a/index-fetch.js b/index-fetch.js index dc6c0d05e3e..fc8e557ce84 100644 --- a/index-fetch.js +++ b/index-fetch.js @@ -1,5 +1,7 @@ 'use strict' +const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global') +const EnvHttpProxyAgent = require('./lib/dispatcher/env-http-proxy-agent') const fetchImpl = require('./lib/web/fetch').fetch module.exports.fetch = function fetch (resource, init = undefined) { @@ -19,3 +21,8 @@ module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket module.exports.MessageEvent = require('./lib/web/websocket/events').MessageEvent module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource + +// Expose the fetch implementation to be enabled in Node.js core via a flag +module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent +module.exports.getGlobalDispatcher = getGlobalDispatcher +module.exports.setGlobalDispatcher = setGlobalDispatcher diff --git a/test/fetch/export-env-proxy-agent.js b/test/fetch/export-env-proxy-agent.js new file mode 100644 index 00000000000..933a6bb530d --- /dev/null +++ b/test/fetch/export-env-proxy-agent.js @@ -0,0 +1,15 @@ +'use strict' + +const { test } = require('node:test') +const assert = require('node:assert') +const undiciFetch = require('../../undici-fetch') + +test('EnvHttpProxyAgent should be part of Node.js bundle', () => { + assert.strictEqual(typeof undiciFetch.EnvHttpProxyAgent, 'function') + assert.strictEqual(typeof undiciFetch.getGlobalDispatcher, 'function') + assert.strictEqual(typeof undiciFetch.setGlobalDispatcher, 'function') + + const agent = new undiciFetch.EnvHttpProxyAgent() + undiciFetch.setGlobalDispatcher(agent) + assert.strictEqual(undiciFetch.getGlobalDispatcher(), agent) +})