Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1ef18bd

Browse filesBrowse files
slushieMylesBorins
authored andcommitted
test: add test for responses to HTTP CONNECT req
See: #6198 PR-URL: #6279 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f6969a1 commit 1ef18bd
Copy full SHA for 1ef18bd

File tree

Expand file treeCollapse file tree

1 file changed

+72
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+72
-0
lines changed
Open diff view settings
Collapse file
+72Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
6+
const server = http.createServer(function(req, res) {
7+
assert(false);
8+
});
9+
server.on('connect', common.mustCall(function(req, socket, firstBodyChunk) {
10+
assert.equal(req.method, 'CONNECT');
11+
assert.equal(req.url, 'example.com:443');
12+
console.error('Server got CONNECT request');
13+
14+
// It is legal for the server to send some data intended for the client
15+
// along with the CONNECT response
16+
socket.write(
17+
'HTTP/1.1 200 Connection established\r\n' +
18+
'Date: Tue, 15 Nov 1994 08:12:31 GMT\r\n' +
19+
'\r\n' +
20+
'Head'
21+
);
22+
23+
var data = firstBodyChunk.toString();
24+
socket.on('data', function(buf) {
25+
data += buf.toString();
26+
});
27+
socket.on('end', function() {
28+
socket.end(data);
29+
});
30+
}));
31+
server.listen(common.PORT, common.mustCall(function() {
32+
const req = http.request({
33+
port: common.PORT,
34+
method: 'CONNECT',
35+
path: 'example.com:443'
36+
}, function(res) {
37+
assert(false);
38+
});
39+
40+
req.on('close', common.mustCall(function() { }));
41+
42+
req.on('connect', common.mustCall(function(res, socket, firstBodyChunk) {
43+
console.error('Client got CONNECT request');
44+
45+
// Make sure this request got removed from the pool.
46+
const name = 'localhost:' + common.PORT;
47+
assert(!http.globalAgent.sockets.hasOwnProperty(name));
48+
assert(!http.globalAgent.requests.hasOwnProperty(name));
49+
50+
// Make sure this socket has detached.
51+
assert(!socket.ondata);
52+
assert(!socket.onend);
53+
assert.equal(socket.listeners('connect').length, 0);
54+
assert.equal(socket.listeners('data').length, 0);
55+
56+
var data = firstBodyChunk.toString();
57+
58+
// test that the firstBodyChunk was not parsed as HTTP
59+
assert.equal(data, 'Head');
60+
61+
socket.on('data', function(buf) {
62+
data += buf.toString();
63+
});
64+
socket.on('end', function() {
65+
assert.equal(data, 'HeadRequestEnd');
66+
server.close();
67+
});
68+
socket.end('End');
69+
}));
70+
71+
req.end('Request');
72+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.