Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: tell the parser about CONNECT responses #6198

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up tests to comply with some best practices
  • Loading branch information
slushie committed Apr 15, 2016
commit 3c295e503a596f487763a1271eefaf7f3f2fd345
54 changes: 18 additions & 36 deletions test/parallel/test-http-connect-head.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var http = require('http');

var serverGotConnect = false;
var clientGotConnect = false;
const common = require('../common');
const assert = require('assert');
const http = require('http');

var server = http.createServer(function(req, res) {
assert(false);
});
server.on('connect', function(req, socket, firstBodyChunk) {
server.on('connect', common.mustCall(function(req, socket, firstBodyChunk) {
assert.equal(req.method, 'CONNECT');
assert.equal(req.url, 'google.com:443');
assert.equal(req.url, 'example.com:443');
console.error('Server got CONNECT request');
serverGotConnect = true;

// It is legal for the server to send some data intended for the client
// along with the CONNECT response
socket.write('HTTP/1.1 200 Connection established\r\n\r\nHead');
socket.write(
'HTTP/1.1 200 Connection established\r\n' +
'Date: Tue, 15 Nov 1994 08:12:31 GMT\r\n' +
'\r\n' +
'Head'
);

var data = firstBodyChunk.toString();
socket.on('data', function(buf) {
Expand All @@ -26,24 +27,20 @@ server.on('connect', function(req, socket, firstBodyChunk) {
socket.on('end', function() {
socket.end(data);
});
});
server.listen(common.PORT, function() {
}));
server.listen(common.PORT, common.mustCall(function() {
var req = http.request({
port: common.PORT,
method: 'CONNECT',
path: 'google.com:443'
path: 'example.com:443'
}, function(res) {
assert(false);
});

var clientRequestClosed = false;
req.on('close', function() {
clientRequestClosed = true;
});
req.on('close', common.mustCall(function() { }));

req.on('connect', function(res, socket, firstBodyChunk) {
req.on('connect', common.mustCall(function(res, socket, firstBodyChunk) {
console.error('Client got CONNECT request');
clientGotConnect = true;

// Make sure this request got removed from the pool.
var name = 'localhost:' + common.PORT;
Expand All @@ -56,15 +53,6 @@ server.listen(common.PORT, function() {
assert.equal(socket.listeners('connect').length, 0);
assert.equal(socket.listeners('data').length, 0);

// the stream.Duplex onend listener
// allow 0 here, so that i can run the same test on streams1 impl
assert(socket.listeners('end').length <= 1);

assert.equal(socket.listeners('free').length, 0);
assert.equal(socket.listeners('close').length, 0);
assert.equal(socket.listeners('error').length, 0);
assert.equal(socket.listeners('agentRemove').length, 0);

var data = firstBodyChunk.toString();

// test that the firstBodyChunk was not parsed as HTTP
Expand All @@ -75,16 +63,10 @@ server.listen(common.PORT, function() {
});
socket.on('end', function() {
assert.equal(data, 'HeadRequestEnd');
assert(clientRequestClosed);
server.close();
});
socket.end('End');
});
}));

req.end('Request');
});

process.on('exit', function() {
assert.ok(serverGotConnect);
assert.ok(clientGotConnect);
});
}));