http-https.js 422 B

12345678910111213141516171819
  1. var http = exports.http = require('http')
  2. var https = exports.https = require('https')
  3. var url = require('url')
  4. exports.get = function(opt, cb) {
  5. return getMod(opt).get(opt, cb)
  6. }
  7. exports.request = function(opt, cb) {
  8. return getMod(opt).request(opt, cb)
  9. }
  10. exports.getModule = getMod
  11. function getMod(opt) {
  12. if (typeof opt === 'string')
  13. opt = url.parse(opt)
  14. return opt.protocol === 'https:' ? https : http
  15. }