Skip to content

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

Open
@waldekmastykarz

Description

@waldekmastykarz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions