joepie91 / node-bhttp

A sane HTTP client library for Node.js with Streams2 support.
62 stars 12 forks source link

Accept url.parse()-compatible object as input #3

Open stevenvachon opened 9 years ago

stevenvachon commented 9 years ago

... in addition to a url string. Good for increased performance when we already have a parsed url handy.

joepie91 commented 9 years ago

What are your thoughts on accepting a url.parse object in place of a URL string, ie. as the first argument? This would remove the need to add yet another option.

stevenvachon commented 9 years ago

It doesn't need to be an option. It could check the type of input:

var url = require("url");

if (typeof input==="string" || input instanceof String===true) {
    input = url.parse(input);
} else if (input instanceof url.constructor !== true) {
    // error
}

This isn't exactly url.parse()-compatible, though. Could also more simply check typeof input==="object" && input.protocol!=null.

Continuing with string input can be convenient and cleaner for most libraries. Also increases similarity with "request" lib.

stevenvachon commented 8 years ago

Use whatwg-url. In Node v7, it'll be accessible via require("url").URL.