Skip to content

Commit

Permalink
Expose EnvHttpProxyAgent to Node.js core bundle, so it can be turned … (
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina authored Apr 23, 2024
1 parent 1c44055 commit 961b76a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index-fetch.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
15 changes: 15 additions & 0 deletions test/fetch/export-env-proxy-agent.js
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 961b76a

Please sign in to comment.