Blame view

node_modules/https-browserify/index.js 717 Bytes
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  var http = require('http')
  var url = require('url')
  
  var https = module.exports
  
  for (var key in http) {
    if (http.hasOwnProperty(key)) https[key] = http[key]
  }
  
  https.request = function (params, cb) {
    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
  }