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

refactor(#2722)!: Drop Interceptors support #2754

Merged
merged 7 commits into from
Feb 18, 2024
Merged

refactor(#2722)!: Drop Interceptors support #2754

merged 7 commits into from
Feb 18, 2024

Conversation

metcoder95
Copy link
Member

This relates to...

#2722

Rationale

Drop support for interceptors feature.

  • Re-Implement Redirect instead of Interceptor
  • Document the recommended chaining approach

Changes

Features

Bug Fixes

Breaking Changes and Deprecations

Status

@metcoder95
Copy link
Member Author

metcoder95 commented Feb 14, 2024

We need to rebase main on top of next; I'll try to do that later Today

@ronag
Copy link
Member

ronag commented Feb 14, 2024

Nice! I think you need to do a rebase.

@ronag
Copy link
Member

ronag commented Feb 14, 2024

@metcoder95 I really appreciate your contributions with this. I'm passionate about these changes but overwhelmed with my current workload.

@metcoder95
Copy link
Member Author

Nice! I think you need to do a rebase.

Its next already up-to-date with main?

@metcoder95 I really appreciate your contributions with this. I'm passionate about these changes but overwhelmed with my current workload.

Happy to help! This cleanup is looking great, happy to help preparing next undici major 🚀

lib/agent.js Outdated
handler
)
)
}
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to move this one level higher to the api methods, i.e. totally exclude from normal dispatch

Copy link
Member Author

Choose a reason for hiding this comment

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

So basically just expose it but not add it directly; then several tests will be affected, I’ll go over them during the weekend then 👍

I’ll split this into two PRs, one to remove all sign of interceptors, and a second one to expose Redirect handler and others in a different way.

Copy link
Member

Choose a reason for hiding this comment

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

You don't actually need to break so many tests if you just move it into the api methods (stream, pipeline and request).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, ok, I didn't get that first; so instead of keeping it at a low level, you suggest adding it to the APIs instead; if I understood correctly, sure 👍

ronag

This comment was marked as resolved.

lib/agent.js Outdated
Comment on lines 99 to 107
return dispatcher.dispatch(
opts,
new RedirectHandler(
dispatcher.dispatch.bind(dispatcher),
this[kMaxRedirections],
opts,
handler
)
)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return dispatcher.dispatch(
opts,
new RedirectHandler(
dispatcher.dispatch.bind(dispatcher),
this[kMaxRedirections],
opts,
handler
)
)
throw new Error('maxRedirection no longer directly supported on Agent')

lib/client.js Outdated Show resolved Hide resolved
Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

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

You can add something like:

// api/api-request.js

function request (opts, callback) {
  if (callback === undefined) {
    return new Promise((resolve, reject) => {
      request.call(this, opts, (err, data) => {
        return err ? reject(err) : resolve(data)
      })
    })
  }

  let maxRedirections = opts?.maxRedirections ?? 0
  if (!Number.isInteger(maxRedirections) || maxRedirections < 0) {
    throw new InvalidArgumentError('maxRedirections must be a positive number')
  }

  let dispatch = (opts, handler) => this.dispatch(opts, handler)
  if (maxRedirections > 0) {
    dispatch = (opts, handler) => dispatch(opts, new RedirectHandler(dispatch, maxRedirections, opts, handler))
  }
    
  try {
    dispatch(opts, new RequestHandler(opts, callback))
  } catch (err) {
    if (typeof callback !== 'function') {
      throw err
    }
    const opaque = opts?.opaque
    queueMicrotask(() => callback(err, { opaque }))
  }
}

@Uzlopak
Copy link
Contributor

Uzlopak commented Feb 17, 2024

@mikicho

Is this relevant for your interceptors project?

@mikicho
Copy link

mikicho commented Feb 17, 2024

@Uzlopak We currently don't support undici directly. Only fetch which uses undici under the hood.

@metcoder95 metcoder95 marked this pull request as ready for review February 17, 2024 13:39
@ronag ronag requested review from mcollina and KhafraDev February 17, 2024 14:36
lib/api/api-connect.js Outdated Show resolved Hide resolved
@ronag ronag merged commit 6c40513 into next Feb 18, 2024
16 of 17 checks passed
@Uzlopak Uzlopak deleted the refactor/2722 branch February 21, 2024 12:41
@ronag ronag mentioned this pull request Feb 25, 2024
13 tasks
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 24, 2024
@ronag ronag mentioned this pull request Jul 3, 2024
7 tasks
@metcoder95 metcoder95 mentioned this pull request Jul 3, 2024
7 tasks
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