@@ -93,7 +93,7 @@ not be emitted.
9393
9494### Event: 'connect'
9595
96- ` function (request, socket) { } `
96+ ` function (request, socket, head ) { } `
9797
9898Emitted each time a client requests a http CONNECT method. If this event isn't
9999listened for, then clients requesting a CONNECT method will have their
@@ -102,14 +102,16 @@ connections closed.
102102* ` request ` is the arguments for the http request, as it is in the request
103103 event.
104104* ` socket ` is the network socket between the server and client.
105+ * ` head ` is an instance of Buffer, the first packet of the tunneling stream,
106+ this may be empty.
105107
106108After this event is emitted, the request's socket will not have a ` data `
107109event listener, meaning you will need to bind to it in order to handle data
108110sent to the server on that socket.
109111
110112### Event: 'upgrade'
111113
112- ` function (request, socket) { } `
114+ ` function (request, socket, head ) { } `
113115
114116Emitted each time a client requests a http upgrade. If this event isn't
115117listened for, then clients requesting an upgrade will have their connections
@@ -118,6 +120,8 @@ closed.
118120* ` request ` is the arguments for the http request, as it is in the request
119121 event.
120122* ` socket ` is the network socket between the server and client.
123+ * ` head ` is an instance of Buffer, the first packet of the upgraded stream,
124+ this may be empty.
121125
122126After this event is emitted, the request's socket will not have a ` data `
123127event listener, meaning you will need to bind to it in order to handle data
@@ -591,7 +595,7 @@ Emitted after a socket is assigned to this request.
591595
592596### Event: 'connect'
593597
594- ` function (response, socket) { } `
598+ ` function (response, socket, head ) { } `
595599
596600Emitted each time a server responds to a request with a CONNECT method. If this
597601event isn't being listened for, clients receiving a CONNECT method will have
@@ -608,13 +612,14 @@ A client server pair that show you how to listen for the `connect` event.
608612 res.writeHead(200, {'Content-Type': 'text/plain'});
609613 res.end('okay');
610614 });
611- proxy.on('connect', function(req, cltSocket) {
615+ proxy.on('connect', function(req, cltSocket, head ) {
612616 // connect to an origin server
613617 var srvUrl = url.parse('http://' + req.url);
614618 var srvSocket = net.connect(srvUrl.port, srvUrl.hostname, function() {
615619 cltSocket.write('HTTP/1.1 200 Connection Established\r\n' +
616620 'Proxy-agent: Node-Proxy\r\n' +
617621 '\r\n');
622+ srvSocket.write(head);
618623 srvSocket.pipe(cltSocket);
619624 cltSocket.pipe(srvSocket);
620625 });
@@ -634,7 +639,7 @@ A client server pair that show you how to listen for the `connect` event.
634639 var req = http.request(options);
635640 req.end();
636641
637- req.on('connect', function(res, socket) {
642+ req.on('connect', function(res, socket, head ) {
638643 console.log('got connected!');
639644
640645 // make a request over an HTTP tunnel
@@ -653,7 +658,7 @@ A client server pair that show you how to listen for the `connect` event.
653658
654659### Event: 'upgrade'
655660
656- ` function (response, socket) { } `
661+ ` function (response, socket, head ) { } `
657662
658663Emitted each time a server responds to a request with an upgrade. If this
659664event isn't being listened for, clients receiving an upgrade header will have
@@ -668,7 +673,7 @@ A client server pair that show you how to listen for the `upgrade` event.
668673 res.writeHead(200, {'Content-Type': 'text/plain'});
669674 res.end('okay');
670675 });
671- srv.on('upgrade', function(req, socket) {
676+ srv.on('upgrade', function(req, socket, head ) {
672677 socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
673678 'Upgrade: WebSocket\r\n' +
674679 'Connection: Upgrade\r\n' +
@@ -693,7 +698,7 @@ A client server pair that show you how to listen for the `upgrade` event.
693698 var req = http.request(options);
694699 req.end();
695700
696- req.on('upgrade', function(res, socket) {
701+ req.on('upgrade', function(res, socket, upgradeHead ) {
697702 console.log('got upgraded!');
698703 socket.end();
699704 process.exit(0);
0 commit comments