您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.js 717B

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