Skip to content

Conversation

DTrombett
Copy link
Contributor

@DTrombett DTrombett commented Nov 21, 2024

This relates to...

The retry and cache handlers do not pass down the context of the onConnect method. This means that using the redirect handler with one of them will not pass the context to the main handler:

request("http://github.com", {
    dispatcher: new Agent().compose(
        interceptors.redirect({ maxRedirections: 1 }),
        interceptors.retry(),
    ),
}).then((res) => console.log(res.context)); // undefined

request("http://github.com", {
    dispatcher: new Agent().compose(
        interceptors.redirect({ maxRedirections: 1 }),
    ),
}).then((res) => console.log(res.context)) // { history: [URL, URL] }

Rationale

Changes

  • Cache handler: used ...args to pass all the args (like in the decorator handler)
  • Retry handler: onConnect is now called on the first connection instead that in the constructor, allowing to pass the context

Features

Bug Fixes

Breaking Changes and Deprecations

Status

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening a PR! Can you please add a unit test?

@DTrombett DTrombett requested a review from mcollina November 21, 2024 17:15
Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

@Uzlopak
Copy link
Contributor

Uzlopak commented Nov 22, 2024

...args is imho not that nice. i think it does not cover in the types or so, that it can have two arguments. only abort.

@DTrombett
Copy link
Contributor Author

I noticed that ...args is what is used in the decorator handler too, so I assumed it would be ok

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit a781473 into nodejs:main Nov 22, 2024
35 of 36 checks passed
@DTrombett DTrombett deleted the fix/connect-context branch November 23, 2024 10:52
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
@github-actions github-actions bot mentioned this pull request Mar 12, 2025
@github-actions github-actions bot mentioned this pull request May 12, 2025
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

Successfully merging this pull request may close these issues.

5 participants