@ -21,6 +21,7 @@
var util = require ( 'util' ) ;
var util = require ( 'util' ) ;
var net = require ( 'net' ) ;
var net = require ( 'net' ) ;
var url = require ( 'url' ) ;
var EventEmitter = require ( 'events' ) . EventEmitter ;
var EventEmitter = require ( 'events' ) . EventEmitter ;
var HTTPParser = process . binding ( 'http_parser' ) . HTTPParser ;
var HTTPParser = process . binding ( 'http_parser' ) . HTTPParser ;
var assert = require ( 'assert' ) . ok ;
var assert = require ( 'assert' ) . ok ;
@ -35,17 +36,39 @@ var debug = common.debug;
var IncomingMessage = require ( '_http_incoming' ) . IncomingMessage ;
var IncomingMessage = require ( '_http_incoming' ) . IncomingMessage ;
var OutgoingMessage = require ( '_http_outgoing' ) . OutgoingMessage ;
var OutgoingMessage = require ( '_http_outgoing' ) . OutgoingMessage ;
var agent = require ( '_http_agent' ) ;
var Agent = require ( '_http_agent' ) ;
var globalAgent = agent . globalAgent ;
function ClientRequest ( options , cb ) {
function ClientRequest ( options , cb ) {
var self = this ;
var self = this ;
OutgoingMessage . call ( self ) ;
OutgoingMessage . call ( self ) ;
options = util . _ extend ( { } , options ) ;
if ( util . isString ( options ) ) {
options = url . parse ( options ) ;
} else {
options = util . _ extend ( { } , options ) ;
}
self . agent = util . isUndefined ( options . agent ) ? globalAgent : options . agent ;
var agent = options . agent ;
var defaultAgent = options . _ defaultAgent || Agent . globalAgent ;
if ( agent === false ) {
agent = new defaultAgent . constructor ( ) ;
} else if ( util . isNullOrUndefined ( agent ) ) {
agent = defaultAgent ;
}
self . agent = agent ;
if ( options . path && / / . test ( options . path ) ) {
// The actual regex is more like /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
// with an additional rule for ignoring percentage-escaped characters
// but that's a) hard to capture in a regular expression that performs
// well, and b) possibly too restrictive for real-world usage. That's
// why it only scans for spaces because those are guaranteed to create
// an invalid request.
throw new TypeError ( 'Request path contains unescaped characters.' ) ;
} else if ( options . protocol && options . protocol !== self . agent . protocol ) {
throw new Error ( 'Protocol:' + options . protocol + ' not supported.' ) ;
}
var defaultPort = options . defaultPort || self . agent . defaultPort ;
var defaultPort = options . defaultPort || self . agent . defaultPort ;
@ -114,8 +137,7 @@ function ClientRequest(options, cb) {
// but only if the Agent will actually reuse the connection!
// but only if the Agent will actually reuse the connection!
// If it's not a keepAlive agent, and the maxSockets==Infinity, then
// If it's not a keepAlive agent, and the maxSockets==Infinity, then
// there's never a case where this socket will actually be reused
// there's never a case where this socket will actually be reused
var agent = self . agent ;
if ( ! self . agent . keepAlive && ! Number . isFinite ( self . agent . maxSockets ) ) {
if ( ! agent . keepAlive && ! Number . isFinite ( agent . maxSockets ) ) {
self . _ last = true ;
self . _ last = true ;
self . shouldKeepAlive = false ;
self . shouldKeepAlive = false ;
} else {
} else {