Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose EnvHttpProxyAgent to Node.js core bundle, so it can be turned … #3148

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
Loading