Configuring HTTP proxy as described in our docs no longer works in Node@18 and @20

Open
#1,646 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
node.js, typescript
Domain
api, networking

Research direction

Start at the FetchOptions interface and the Client.initWithMiddleware entry point described in the report, then trace how Node 18/20 fetch options reach requests. Support the undici ProxyAgent dispatcher alongside the documented configuration and verify that requests are intercepted by the specified HTTP proxy.

Written by the indexing model from the issue text.

Description

Bug Report

Description

Since v18, Node ships with a native fetch client. This client requires a different way to specify an HTTP proxy than what we've been supporting in our SDKs so far.

To specify an HTTP proxy for Node's fetch, you need to use the following code (tested on Node v18.19 and v20.11):

import { ProxyAgent } from 'undici';
import { Client } from '@microsoft/microsoft-graph-client';

const dispatcher = new ProxyAgent(process.env.https_proxy);
const fetchOptions = {
  dispatcher
};

Client.initWithMiddleware({
  middleware,
  fetchOptions
});

What's noteworthy:

  • we specify HTTP proxy using dispatcher instead of agent (agent is ignored on requests, which makes it hard to debug)
  • the ProxyAgent dispatcher comes from undici which seems to be maintained by Node folks. The ProxyAgent is incompatible with other agents that we used to use in the past.

We should update our FetchOptions interface to support specifying dispatcher.

Console Errors: no

Steps to Reproduce

  1. Configure an http proxy as specified in our docs

Expected behavior: web requests intercepted by the specified proxy

Actual behavior: web requests passed through without being intercepted

Additional Context

Usage Information

SDK Version - 3.06

  • Node (Check, if using Node version of SDK)

Node Version - v18.19 and v20.11

Dominant language
TypeScript
Stars
833
Forks
240
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoftgraph/msgraph-sdk-javascript

All issues in microsoftgraph/msgraph-sdk-javascript

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.