var http = require('http');
var tls = require('tls');
var util = require('./index');
var config = require('../config');

function connect(options, callback) {
	var done, timeout;
	var headers = options.headers = options.headers || {};
	options.method = 'CONNECT';
	options.headers['proxy-connection'] = 'keep-alive';
	options.agent = false;
	headers['user-agent'] = headers['user-agent'] || (config.name + '/' + config.version);
	options.port = options.port || 8888;
	
	if (headers.host && headers.host.indexOf(':') == -1) {
		headers.host += options.isHttps ? ':443' : ':80';
	}
	
	timeout = util.setTimeout(function() {
		execCallback(new Error('timeout'));
	});
	
	function execCallback(err, socket) {
		clearTimeout(timeout);
		!done && callback(err, socket);
		done = true;
	}
	
	var client = http.request(options)
						.on('connect', function (res, socket, head) {
							socket.on('error', util.noop);
							execCallback(null, options.isHttps ? tls.connect({
						        rejectUnauthorized: false,
						        socket: socket
						    }).on('error', util.noop) : socket);
						}).on('error', execCallback);
	client.end();
	return client;
}

module.exports = connect;
@@ -467,36 +467,274 @@
 %0A%09%0A%09
-if (headers.host && headers.
+function execCallback(err, socket) %7B%0A%09%09timeout && clearTimeout(timeout);%0A%09%09!done && callback(err, socket);%0A%09%09done = true;%0A%09%7D%0A%09%0A%09var host = headers.host;%0A%09if (!host %7C%7C typeof host != 'string') %7B%0A%09  return execCallback(new Error('missing headers.host'));%0A  %7D%0A  %0A  if (
 host
@@ -756,18 +756,20 @@
 = -1) %7B%0A
-%09%09
+    
 headers.
@@ -810,22 +810,25 @@
  ':80';%0A
-%09%7D%0A%09%0A%09
+  %7D%0A  %0A  
 timeout 
@@ -858,18 +858,20 @@
 ion() %7B%0A
-%09%09
+    
 execCall
@@ -902,129 +902,13 @@
 ));%0A
-%09%7D);%0A%09%0A%09function execCallback(err, socket) %7B%0A%09%09clearTimeout(timeout);%0A%09%09!done && callback(err, socket);%0A%09%09done = true;%0A%09%7D
+  %7D);
 %0A%09%0A%09
@@ -1131,16 +1131,62 @@
  false,%0A
+%09%09%09%09%09%09        servername: host.split(':')%5B0%5D,%0A
 %09%09%09%09%09%09  

Add servername to tls.connect