Revision b0c0111b lib/http.js

View differences:

lib/http.js
1067 1067
  }
1068 1068
  if (this.sockets[name].length < this.maxSockets) {
1069 1069
    // If we are under maxSockets create a new one.
1070
    req.onSocket(this.createSocket(name, host, port, localAddress));
1070
    req.onSocket(this.createSocket(name, host, port, localAddress, req));
1071 1071
  } else {
1072 1072
    // We are over limit so we'll add it to the queue.
1073 1073
    if (!this.requests[name]) {
......
1076 1076
    this.requests[name].push(req);
1077 1077
  }
1078 1078
};
1079
Agent.prototype.createSocket = function(name, host, port, localAddress) {
1079
Agent.prototype.createSocket = function(name, host, port, localAddress, req) {
1080 1080
  var self = this;
1081 1081
  var options = util._extend({}, self.options);
1082 1082
  options.port = port;
1083 1083
  options.host = host;
1084 1084
  options.localAddress = localAddress;
1085

  
1086
  options.servername = host;
1087
  if (req) {
1088
    var hostHeader = req.getHeader('host');
1089
    if (hostHeader) {
1090
      options.servername = hostHeader.replace(/:.*$/, '');
1091
    }
1092
  }
1093

  
1085 1094
  var s = self.createConnection(options);
1086 1095
  if (!self.sockets[name]) {
1087 1096
    self.sockets[name] = [];
......
1122 1131
    }
1123 1132
  }
1124 1133
  if (this.requests[name] && this.requests[name].length) {
1134
    var req = this.requests[name][0];
1125 1135
    // If we have pending requests and a socket gets closed a new one
1126
    this.createSocket(name, host, port, localAddress).emit('free');
1136
    this.createSocket(name, host, port, localAddress, req).emit('free');
1127 1137
  }
1128 1138
};
1129 1139

  

Also available in: Unified diff