1 |
3a515b92
|
cagy
|
var http = require('http')
|
2 |
|
|
var url = require('url')
|
3 |
|
|
|
4 |
|
|
var https = module.exports
|
5 |
|
|
|
6 |
|
|
for (var key in http) {
|
7 |
|
|
if (http.hasOwnProperty(key)) https[key] = http[key]
|
8 |
|
|
}
|
9 |
|
|
|
10 |
|
|
https.request = function (params, cb) {
|
11 |
|
|
params = validateParams(params)
|
12 |
|
|
return http.request.call(this, params, cb)
|
13 |
|
|
}
|
14 |
|
|
|
15 |
|
|
https.get = function (params, cb) {
|
16 |
|
|
params = validateParams(params)
|
17 |
|
|
return http.get.call(this, params, cb)
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
function validateParams (params) {
|
21 |
|
|
if (typeof params === 'string') {
|
22 |
|
|
params = url.parse(params)
|
23 |
|
|
}
|
24 |
|
|
if (!params.protocol) {
|
25 |
|
|
params.protocol = 'https:'
|
26 |
|
|
}
|
27 |
|
|
if (params.protocol !== 'https:') {
|
28 |
|
|
throw new Error('Protocol "' + params.protocol + '" not supported. Expected "https:"')
|
29 |
|
|
}
|
30 |
|
|
return params
|
31 |
|
|
}
|