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

fix: pass down context in onConnect #3858

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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?

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.

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