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

A few questions #893

Closed
szmarczak opened this issue Jul 19, 2021 · 4 comments
Closed

A few questions #893

szmarczak opened this issue Jul 19, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@szmarczak
Copy link
Member

  1. We can provide connect function or connect options but not both. Why?
  2. Why options.origin and not options.protocol, options.host and options.port?
  3. undici/lib/core/request.js

    Lines 100 to 127 in aebbb5d

    if (typeof handler.onConnect !== 'function') {
    throw new InvalidArgumentError('invalid onConnect method')
    }
    if (typeof handler.onError !== 'function') {
    throw new InvalidArgumentError('invalid onError method')
    }
    if (typeof handler.onBodySent !== 'function' && handler.onBodySent !== undefined) {
    throw new InvalidArgumentError('invalid onBodySent method')
    }
    if (this.upgrade || this.method === 'CONNECT') {
    if (typeof handler.onUpgrade !== 'function') {
    throw new InvalidArgumentError('invalid onUpgrade method')
    }
    } else {
    if (typeof handler.onHeaders !== 'function') {
    throw new InvalidArgumentError('invalid onHeaders method')
    }
    if (typeof handler.onData !== 'function') {
    throw new InvalidArgumentError('invalid onData method')
    }
    if (typeof handler.onComplete !== 'function') {
    throw new InvalidArgumentError('invalid onComplete method')
    }
    these checks are missing in RedirectHandler
  4. Isn't
    this.servername = util.getServerName(this.host)
    moot because
    this.host = null
  5. nitpick:
    if (hostname.startsWith('[')) {
    is slower by ~20% than hostname[0] === '['
  6. undici/lib/client.js

    Lines 1397 to 1399 in aebbb5d

    // TODO: An HTTP/1.1 user agent MUST NOT preface
    // or follow a request with an extra CRLF.
    // https://tools.ietf.org/html/rfc7230#section-3.5
    can be removed because ee64b39?
  7. Can we avoid object allocation somehow? I think that should improve the performance as well. I mean

    undici/lib/client.js

    Lines 1439 to 1449 in aebbb5d

    writeStream({ client, request, socket, contentLength, header, expectsPayload })
    } else if (util.isStrictIterable(body)) {
    writeIterable({ client, request, socket, contentLength, header, expectsPayload })
    } else {
    assert(false)
    }
    return true
    }
    function writeStream ({ client, request, socket, contentLength, header, expectsPayload }) {
  8. // TODO (fix): Write a comment why this is needed?
    this reassures us that there is no body sent on redirect
  9. I wonder if

    undici/index.js

    Lines 40 to 65 in aebbb5d

    if (typeof opts === 'function') {
    handler = opts
    opts = null
    }
    if (!url || (typeof url !== 'string' && typeof url !== 'object' && !(url instanceof URL))) {
    throw new InvalidArgumentError('invalid url')
    }
    if (opts != null && typeof opts !== 'object') {
    throw new InvalidArgumentError('invalid opts')
    }
    if (opts && opts.path != null) {
    if (typeof opts.path !== 'string') {
    throw new InvalidArgumentError('invalid opts.path')
    }
    url = new URL(opts.path, util.parseOrigin(url))
    } else {
    if (!opts) {
    opts = typeof url === 'object' ? url : {}
    }
    url = util.parseURL(url)
    }
    can be removed
@szmarczak szmarczak added the enhancement New feature or request label Jul 19, 2021
@mcollina
Copy link
Member

The vast majority of those are PRs that could be sent 🙏❤️

@ronag
Copy link
Member

ronag commented Jul 20, 2021

  1. Because if you provide a method you can save all params in the closure. Thus you don't need both.
  2. Simplicity I guess...
  3. PR. A validateHandler util?
  4. host is set through processHeader
  5. PR
  6. PR
  7. I think V8 might handle that already. Don't think it makes much of a diff.
  8. PR
  9. Why you think that?

@joaopedrocampos
Copy link
Contributor

Hey guys, decided to try the fixes that @ronag said that needed a PR, in this case, the items 3 and 5

  • Change startsWith for [0] ===
  • Create an util function that validates handler (I am not sure if the solution I did is the best but I think this is a better discussion for the PR)

PR: #894

@szmarczak
Copy link
Member Author

  1. Why you think that?

Sorry, my bad. I thought the code was duplicated somewhere else.

  1. host is set through processHeader

Right 👍🏼

  1. Because if you provide a method you can save all params in the closure. Thus you don't need both.

Hmm... makes sense.

Thanks for answering!

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

No branches or pull requests

4 participants