镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

url + http/https: weird api between these module #8722

Closed

Description

@yorkie

url.format will return an object owns pathname rather than path, however http.request and https.request do accept path rather than pathname.

sometimes, we would seem to write our program:

var urlobj = url.format('https://github.com/yorkie');
http.request(urlobj, function (res) {
  // actually we get the response from https://github.com/
});

path is missing, yeah actually we can add urlobj.path = urlobj.pathname for now, it does work as well, but it's a weird behavior in api level imo.

I'm guessing we should unify these two/three functions definitely, of course backward compatible with url module.

Activity

  1. yorkie commented on Nov 13, 2014

    @yorkie
    Author

    sorry, i mean url.format doesn't accept path, the case in real world is https://github.com/yorkie/node-httpmocker/blob/master/index.js#L39.

  2. yorkie commented on Nov 20, 2014

    @yorkie
    Author

    any thoughts from core team?

  3. indutny commented on Nov 20, 2014

    @indutny
    Member

    What node.js version are we talking about?

  4. indutny commented on Nov 20, 2014

    @indutny
    Member

    Also, could you please paste a complete example of this thing, i.e. the code that works with http module and doesn't with https.

  5. yorkie commented on Nov 20, 2014

    @yorkie
    Author

    From the latest stable docs:

    the complete example should be written at https://github.com/yorkie/node-httpmocker/blob/master/index.js#L39, now i copy/paste it here:

    function mockRequest(options, callback) {
      var requesturl = url.format(options);
      // ...
    }

    The function mockRequest will be called like http.request or https.request because this function is mocking these 2 official APIs.

    Hence that the progress is: calling mockRequest({host: 'github.com', path: '/induty'}) would be equal to url.format({host: 'github.com', path: '/induty'}), and path would be ignored by url.format at that moment. To let example work, we have to add a line: options.pathname = options.path.

    To reproduce this on v0.10.33:

    > url.format({protocol:'http',host:'github.com',path:'/induty'})
    'https://github.com/'
    > url.format({protocol:'http',host:'github.com',pathname:'/induty'})
    'https://github.com/induty'
  6. yorkie commented on Nov 20, 2014

    @yorkie
    Author

    and this actually is not related http or https, but never mind, it's not a bug just wanna get thoughts from core team 🌸

  7. indutny commented on Nov 20, 2014

    @indutny
    Member

    Oh, I see. It doesn't look like there could be a reason why it should not support path as well as pathname. Mind submitting a PR with test? ;)

  8. yorkie commented on Nov 20, 2014

    @yorkie
    Author

    bingo, then would do that later 🍒

  9. chrisdickinson commented on Dec 2, 2014

    @chrisdickinson

    Fixed in d312b6d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions