Skip to content

Commit 2350f73

Browse files
http: updated tests and close connection
1 parent e7972d5 commit 2350f73

14 files changed

+15
-11
lines changed

lib/_http_server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
10241024
// A server MUST respond with a 400 (Bad Request) status code to any
10251025
// HTTP/1.1 request message that lacks a Host header field
10261026
if (req.headers.host === undefined) {
1027-
res.writeHead(400);
1027+
res.writeHead(400, ['Connection', 'close']);
10281028
res.end();
10291029
return 0;
10301030
}

test/parallel/test-http-keep-alive-drop-requests.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const assert = require('assert');
88
function request(socket) {
99
socket.write('GET / HTTP/1.1\r\n');
1010
socket.write('Connection: keep-alive\r\n');
11+
socket.write('Host: localhost\r\n');
1112
socket.write('\r\n\r\n');
1213
}
1314

test/parallel/test-http-keep-alive-max-requests.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ function writeRequest(socket, withBody) {
2424
socket.write('POST / HTTP/1.1\r\n');
2525
socket.write('Connection: keep-alive\r\n');
2626
socket.write('Content-Type: text/plain\r\n');
27+
socket.write('Host: localhost\r\n');
2728
socket.write(`Content-Length: ${bodySent.length}\r\n\r\n`);
2829
socket.write(`${bodySent}\r\n`);
2930
socket.write('\r\n\r\n');
3031
} else {
3132
socket.write('GET / HTTP/1.1\r\n');
3233
socket.write('Connection: keep-alive\r\n');
34+
socket.write('Host: localhost\r\n');
3335
socket.write('\r\n\r\n');
3436
}
3537
}

test/parallel/test-http-request-host-header.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const server = http.createServer(common.mustNotCall((req, res) => {
1414
server.listen(0, common.mustCall(() => {
1515
http.get({ port: server.address().port, headers: [] }, (res) => {
1616
assert.strictEqual(res.statusCode, 400);
17+
assert.strictEqual(res.headers.connection, 'close');
1718
res.resume().on('end', common.mustCall(() => {
1819
server.close();
1920
}));

test/parallel/test-http-server-close-all.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ server.listen(0, function() {
5050

5151
client2.on('close', common.mustCall());
5252

53-
client2.write('GET / HTTP/1.1\r\n\r\n');
53+
client2.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
5454
}));
5555

5656
client1.on('close', common.mustCall());

test/parallel/test-http-server-close-idle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ server.listen(0, function() {
6060
client2Closed = true;
6161
}));
6262

63-
client2.write('GET / HTTP/1.1\r\n\r\n');
63+
client2.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
6464
}));
6565

6666
client1.on('close', common.mustCall(() => {

test/parallel/test-http-server-headers-timeout-keepalive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { connect } = require('net');
1212

1313
function performRequestWithDelay(client, firstDelay, secondDelay, closeAfter) {
1414
client.resume();
15-
client.write('GET / HTTP/1.1\r\n');
15+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n');
1616

1717
setTimeout(() => {
1818
client.write('Connection: ');

test/parallel/test-http-server-headers-timeout-pipelining.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ server.listen(0, common.mustCall(() => {
6666

6767
// Send two requests using pipelining. Delay before finishing the second one
6868
client.resume();
69-
client.write('GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\nGET / HTTP/1.1\r\nConnection: ');
69+
client.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\nGET / HTTP/1.1\r\nHost: localhost\r\nConnection: ');
7070

7171
// Complete the request
7272
setTimeout(() => {

test/parallel/test-http-server-request-timeout-pipelining.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ server.listen(0, common.mustCall(() => {
6060

6161
// Send two requests using pipelining. Delay before finishing the second one
6262
client.resume();
63-
client.write('GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\nGET / HTTP/1.1\r\nConnection: ');
63+
client.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\nGET / HTTP/1.1\r\nHost: localhost\r\nConnection: ');
6464

6565
// Complete the request
6666
setTimeout(() => {

test/parallel/test-http-server-request-timeouts-mixed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { connect } = require('net');
77

88
// This test validates that request are correct checked for both requests and headers timeout in various situations.
99

10-
const requestBodyPart1 = 'POST / HTTP/1.1\r\nContent-Length: 20\r\n';
10+
const requestBodyPart1 = 'POST / HTTP/1.1\r\nHost: localhost\r\nContent-Length: 20\r\n';
1111
const requestBodyPart2 = 'Connection: close\r\n\r\n1234567890';
1212
const requestBodyPart3 = '1234567890';
1313

test/parallel/test-https-host-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const httpsServer = https.createServer({
2525
}
2626
res.writeHead(200, {});
2727
res.end('ok');
28-
}, 9)).listen(0, common.mustCall(function(err) {
28+
}, 6)).listen(0, common.mustCall(function(err) {
2929
debug(`test https server listening on port ${this.address().port}`);
3030
assert.ifError(err);
3131
https.get({

test/parallel/test-https-keep-alive-drop-requests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const tls = require('tls');
1313
const { readKey } = require('../common/fixtures');
1414

1515
function request(socket) {
16-
socket.write('GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n\r\n');
16+
socket.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n\r\n');
1717
}
1818

1919
// https options

test/parallel/test-https-server-close-all.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ server.listen(0, function() {
6060

6161
client2.on('close', common.mustCall());
6262

63-
client2.write('GET / HTTP/1.1\r\n\r\n');
63+
client2.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
6464
}));
6565

6666
client1.on('close', common.mustCall());

test/parallel/test-https-server-close-idle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ server.listen(0, function() {
7070
client2Closed = true;
7171
}));
7272

73-
client2.write('GET / HTTP/1.1\r\n\r\n');
73+
client2.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n');
7474
}));
7575

7676
client1.on('close', common.mustCall(() => {

0 commit comments

Comments
 (0)