"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm-registry-client/lib/initialize.js" (11 Apr 2017, 2208 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var crypto = require('crypto')
    2 var HttpAgent = require('http').Agent
    3 var HttpsAgent = require('https').Agent
    4 
    5 var pkg = require('../package.json')
    6 
    7 module.exports = initialize
    8 
    9 function initialize (uri, method, accept, headers) {
   10   if (!this.config.sessionToken) {
   11     this.config.sessionToken = crypto.randomBytes(8).toString('hex')
   12     this.log.verbose('request id', this.config.sessionToken)
   13   }
   14 
   15   var opts = {
   16     url: uri,
   17     method: method,
   18     headers: headers,
   19     localAddress: this.config.proxy.localAddress,
   20     strictSSL: this.config.ssl.strict,
   21     cert: this.config.ssl.certificate,
   22     key: this.config.ssl.key,
   23     ca: this.config.ssl.ca,
   24     agent: getAgent.call(this, uri.protocol)
   25   }
   26 
   27   // allow explicit disabling of proxy in environment via CLI
   28   //
   29   // how false gets here is the CLI's problem (it's gross)
   30   if (this.config.proxy.http === false) {
   31     opts.proxy = null
   32   } else {
   33     // request will not pay attention to the NOPROXY environment variable if a
   34     // config value named proxy is passed in, even if it's set to null.
   35     var proxy
   36     if (uri.protocol === 'https:') {
   37       proxy = this.config.proxy.https
   38     } else {
   39       proxy = this.config.proxy.http
   40     }
   41     if (typeof proxy === 'string') opts.proxy = proxy
   42   }
   43 
   44   headers.version = this.version || pkg.version
   45   headers.accept = accept
   46 
   47   if (this.refer) headers.referer = this.refer
   48 
   49   headers['npm-session'] = this.config.sessionToken
   50   headers['user-agent'] = this.config.userAgent
   51 
   52   return opts
   53 }
   54 
   55 function getAgent (protocol) {
   56   if (protocol === 'https:') {
   57     if (!this.httpsAgent) {
   58       this.httpsAgent = new HttpsAgent({
   59         keepAlive: true,
   60         maxSockets: this.config.maxSockets,
   61         localAddress: this.config.proxy.localAddress,
   62         rejectUnauthorized: this.config.ssl.strict,
   63         ca: this.config.ssl.ca,
   64         cert: this.config.ssl.certificate,
   65         key: this.config.ssl.key
   66       })
   67     }
   68 
   69     return this.httpsAgent
   70   } else {
   71     if (!this.httpAgent) {
   72       this.httpAgent = new HttpAgent({
   73         keepAlive: true,
   74         maxSockets: this.config.maxSockets,
   75         localAddress: this.config.proxy.localAddress
   76       })
   77     }
   78 
   79     return this.httpAgent
   80   }
   81 }