File tree 1 file changed +14
-19
lines changed
1 file changed +14
-19
lines changed Original file line number Diff line number Diff line change @@ -29,30 +29,25 @@ var srv = http.createServer(function(req, res) {
29
29
res . end ( '1' ) ;
30
30
} ) . listen ( 8000 ) ;
31
31
32
+ srv . on ( 'connection' , function ( s ) {
33
+ s . pipe ( process . stdout ) ;
34
+ } ) ;
35
+
32
36
srv . on ( 'upgrade' , function ( req , socket , head ) {
37
+
33
38
var options = {
34
39
port : 9090 ,
35
40
hostname : '127.0.0.1' ,
36
41
headers : req . headers
37
42
}
38
- var req = http . request ( options ) ;
39
- req . end ( ) ;
40
- socket . on ( 'data' , function ( d ) {
41
- console . log ( 'yoo' ) ;
42
- console . log ( d ) ;
43
- } ) ;
44
- var s ;
45
- req . on ( 'socket' , function ( ss ) {
46
- s = ss ;
47
- } ) ;
48
- req . on ( 'upgrade' , function ( res , sock , hd ) {
49
- /*console.log(hd.toString('utf-8'));
50
- var str = Object.keys(res.headers).map(function(i) {
51
- return i + ": " + res.headers[i];
52
- }).join('\r\n');
53
- socket.write("HTTP/1.1 101 Switching Protocols\r\n" + str);
54
-
55
- socket.write(hd);
56
- socket.pipe(sock).pipe(socket);*/
43
+ var r = http . request ( options ) ;
44
+
45
+ r . on ( 'upgrade' , function ( res , sock , hd ) {
46
+ if ( hd && hd . length ) sock . unshift ( hd ) ;
47
+
48
+
49
+ socket . pipe ( sock ) . pipe ( socket ) ;
57
50
} ) ;
51
+
52
+ r . end ( ) ;
58
53
} ) ;
You can’t perform that action at this time.
0 commit comments