var tls = require('tls'); var http = require('http'); var inherits = require('util').inherits; function Server(opts, requestListener){ if (!(this instanceof Server)) return new Server(opts, requestListener); if (process.features.tls_npn && !opts.NPNProtocols) { opts.NPNProtocols = ['http/1.1', 'http/1.0'] ; } tls.Server.call(this, opts, http._connectionListener); this.httpAllowHalfOpen = false ; if (requestListener) { this.addListener('request', requestListener); } } inherits(Server, tls.Server); exports.Server = Server; exports.createServer = function (opts, requestListener){ return new Server(opts, requestListener); } ; function createConnection(){ var options = { } ; if (typeof arguments[0] === 'object') { options = arguments[0]; } else if (typeof arguments[1] === 'object') { options = arguments[1]; _AN_Write_port('port', options, false , arguments[0]); } else if (typeof arguments[2] === 'object') { options = arguments[2]; _AN_Write_port('port', options, false , arguments[0]); _AN_Write_host('host', options, false , arguments[1]); } else { if (typeof arguments[0] === 'number') { _AN_Write_port('port', options, false , arguments[0]); } if (typeof arguments[1] === 'string') { _AN_Write_host('host', options, false , arguments[1]); } } return tls.connect(options); } function Agent(options){ http.Agent.call(this, options); this.createConnection = createConnection; } inherits(Agent, http.Agent); Agent.prototype.defaultPort = 443; var globalAgent = new Agent(); exports.globalAgent = globalAgent; exports.Agent = Agent; exports.request = function (options, cb){ if (_AN_Read_protocol('protocol', options) && _AN_Read_protocol('protocol', options) !== 'https:') { throw new Error('Protocol:' + (_AN_Read_protocol('protocol', options)) + ' not supported.') } if (options.agent === undefined) { options.agent = globalAgent; } options.createConnection = createConnection; options.defaultPort = options.defaultPort || 443; return new http.ClientRequest(options, cb); } ; exports.get = function (options, cb){ var req = exports.request(options, cb); req.end(); return req; } ;