https: make https.get() accept a URL

https.get() now accepts either a URL (as a string) or an options object.

Refs #2859.
Fixes #3882.
This commit is contained in:
koichik
2012-08-18 14:18:02 +09:00
committed by Ben Noordhuis
parent 59011448c0
commit 752ac320ae
3 changed files with 70 additions and 3 deletions

View File

@@ -21,6 +21,7 @@
var tls = require('tls');
var http = require('http');
var url = require('url');
var inherits = require('util').inherits;
function Server(opts, requestListener) {
@@ -88,6 +89,10 @@ exports.globalAgent = globalAgent;
exports.Agent = Agent;
exports.request = function(options, cb) {
if (typeof options === 'string') {
options = url.parse(options);
}
if (options.protocol && options.protocol !== 'https:') {
throw new Error('Protocol:' + options.protocol + ' not supported.');
}