Skip to content

Commit 1a7bef0

Browse files
committed
mm test file
1 parent e45bfd6 commit 1a7bef0

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

Diff for: ttest.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,25 @@ var srv = http.createServer(function(req, res) {
2929
res.end('1');
3030
}).listen(8000);
3131

32+
srv.on('connection', function(s) {
33+
s.pipe(process.stdout);
34+
});
35+
3236
srv.on('upgrade', function(req, socket, head) {
37+
3338
var options = {
3439
port: 9090,
3540
hostname: '127.0.0.1',
3641
headers: req.headers
3742
}
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);
5750
});
51+
52+
r.end();
5853
});

0 commit comments

Comments
 (0)