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

feat: dispatcher _buildConnector() method #3602

Closed
wants to merge 2 commits into from
Closed

feat: dispatcher _buildConnector() method #3602

wants to merge 2 commits into from

Conversation

zdm
Copy link

@zdm zdm commented Sep 13, 2024

This relates to...

#3486

Rationale

This patch allows to access buildConnector options in the DispatcherBase subclasses.
This will allows to create custom connect function in subclasses using buiildConnector options.

Changes

  1. _buildConnector() protected method added to DispatcherBase.
  2. buildConnector calls changed from direct use to use this._buildConnector() method.
  3. helper function configureSocket() added. It sets socket no delay and keep alive based on passed options.

Features

It is too hard to make connect callback receive full list of connect options.
At least I have no idea how to implement it on current code base without deep refactoring.
This patch helps to solve this problem in dispatcher subclasses, that will be enough for most of developers.

Use case:

import Client from 'undici/dispatcher/client'
import { configureSocket } from 'undici/core/connect'

export default class extends Client {

  _buildConnector (buildOptions) {

    // create custom connector
    if (this.proxy) {
      return async (options, callback) => {
        const socket = await this._createSocket(buildOptions, options)

        callback(configureSocket(socket))
      }

    // or fallback to the default behavior
    } else {
      return super._buildConnector(buildOptions)
    }
  }
}

Bug Fixes

#3486

Breaking Changes and Deprecations

Status

@mcollina
Copy link
Member

why is this needed?

@zdm
Copy link
Author

zdm commented Sep 14, 2024

This is needed if I want to create custom dispatcher and get access to buildConnector options (with resolved default values), please look at related issue.

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.

I don't think this is a good idea...

@zdm
Copy link
Author

zdm commented Sep 14, 2024

Why nor? Do you have arguments?
"buildConnector" is used in subclasses constructor, why not provide this standard functionality as private method?
I think this is obvious

@zdm zdm closed this by deleting the head repository Sep 15, 2024
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.

3 participants