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

Request Agent from RequestInit not used and therefore not propagted #1342

Open
sonewman opened this issue Jun 3, 2024 · 1 comment
Open

Comments

@sonewman
Copy link

sonewman commented Jun 3, 2024

When instantiating a Request the agent option is not set on the Request, it can only be set manually on the request object.

This introduces the additional issue that the agent is not propagated when another Request is cloned or instantiated from it.

To Reproduce Steps to reproduce the behavior:

const agent = new Agent();
const request1 = new PonyfillRequest('http://a', {
  agent,
});

// request1.agent === undefined

request1.agent = agent;

const request2 = request1.clone();

// request2.agent === undefined

Expected behavior

I would expect the agent to be set from the supplied arguments (since it is defined in the type definitions)
I would expect the agent to be propagated to clones of said request

Environment:

  • OS:
  • package-name...:
  • NodeJS:

Additional context

@FoxBuru
Copy link

FoxBuru commented Jul 1, 2024

I'm not really sure if this is the most compatible option given what's supported now on standard Fetch API. Apparently, the way to set an Agent while conforming to that standard, looks like:

const sampleRequestInit : RequestInit {
   ...otherArgs,
   dispatcher: new Agent({ 
     connect: {
       rejectUnauthorized: this.rejectUnauthorized
     }
   }),
}

Which runs on node >= 20 (and, for this concrete library, by enabling both skipPolyfill and useNodeFetch). For previous versions, the node-fetch shim was used to provide a somewhat compatible contract with the Fetch API.

Given this library tries to provide an abstraction not only over Fetch API, but also with other fetch-look-alike implementations like node-libcurl, I'm not sure how to reconcile those two views. Regardless, to maximize compatibility and stability, sounds like a good idea to keep this issue open, until either a fix or a decision is reached on how something like that can be achieved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants