]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/lib/initialize.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npm-registry-client / lib / initialize.js
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 }