2017-12-10 21:51:33 +01:00
|
|
|
var http = require('http')
|
|
|
|
var url = require('url')
|
2017-05-03 15:35:00 +02:00
|
|
|
|
2017-12-10 21:51:33 +01:00
|
|
|
var https = module.exports
|
2017-05-03 15:35:00 +02:00
|
|
|
|
|
|
|
for (var key in http) {
|
2017-12-10 21:51:33 +01:00
|
|
|
if (http.hasOwnProperty(key)) https[key] = http[key]
|
|
|
|
}
|
2017-05-03 15:35:00 +02:00
|
|
|
|
|
|
|
https.request = function (params, cb) {
|
2017-12-10 21:51:33 +01:00
|
|
|
params = validateParams(params)
|
|
|
|
return http.request.call(this, params, cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
https.get = function (params, cb) {
|
|
|
|
params = validateParams(params)
|
|
|
|
return http.get.call(this, params, cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateParams (params) {
|
|
|
|
if (typeof params === 'string') {
|
|
|
|
params = url.parse(params)
|
|
|
|
}
|
|
|
|
if (!params.protocol) {
|
|
|
|
params.protocol = 'https:'
|
|
|
|
}
|
|
|
|
if (params.protocol !== 'https:') {
|
|
|
|
throw new Error('Protocol "' + params.protocol + '" not supported. Expected "https:"')
|
|
|
|
}
|
|
|
|
return params
|
2017-05-03 15:35:00 +02:00
|
|
|
}
|