Skip to content

Commit a4c5f5f

Browse files
authored
test: add host header for net connection (fastify#4536)
1 parent 842dc13 commit a4c5f5f

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

test/close.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ t.test('Current opened connection should continue to work after closing and retu
220220

221221
const port = fastify.server.address().port
222222
const client = net.createConnection({ port }, () => {
223-
client.write('GET / HTTP/1.1\r\n\r\n')
223+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
224224

225225
client.once('data', data => {
226226
t.match(data.toString(), /Connection:\s*keep-alive/i)
227227
t.match(data.toString(), /200 OK/i)
228228

229-
client.write('GET / HTTP/1.1\r\n\r\n')
229+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
230230

231231
client.once('data', data => {
232232
t.match(data.toString(), /Connection:\s*close/i)
@@ -259,7 +259,7 @@ t.test('Current opened connection should NOT continue to work after closing and
259259

260260
const port = fastify.server.address().port
261261
const client = net.createConnection({ port }, () => {
262-
client.write('GET / HTTP/1.1\r\n\r\n')
262+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
263263

264264
client.on('error', function () {
265265
// Dependending on the Operating System
@@ -275,7 +275,7 @@ t.test('Current opened connection should NOT continue to work after closing and
275275
t.match(data.toString(), /Connection:\s*keep-alive/i)
276276
t.match(data.toString(), /200 OK/i)
277277

278-
client.write('GET / HTTP/1.1\r\n\r\n')
278+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
279279
})
280280
})
281281
})

test/maxRequestsPerSocket.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ test('maxRequestsPerSocket on node version >= 16.10.0', { skip }, t => {
2222

2323
const port = fastify.server.address().port
2424
const client = net.createConnection({ port }, () => {
25-
client.write('GET / HTTP/1.1\r\n\r\n')
25+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
2626

2727
client.once('data', data => {
2828
t.match(data.toString(), /Connection:\s*keep-alive/i)
2929
t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
3030
t.match(data.toString(), /200 OK/i)
3131

32-
client.write('GET / HTTP/1.1\r\n\r\n')
32+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3333

3434
client.once('data', data => {
3535
t.match(data.toString(), /Connection:\s*close/i)
3636
t.match(data.toString(), /200 OK/i)
3737

38-
client.write('GET / HTTP/1.1\r\n\r\n')
38+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3939

4040
client.once('data', data => {
4141
t.match(data.toString(), /Connection:\s*close/i)
@@ -63,21 +63,21 @@ test('maxRequestsPerSocket zero should behave same as null', { skip }, t => {
6363

6464
const port = fastify.server.address().port
6565
const client = net.createConnection({ port }, () => {
66-
client.write('GET / HTTP/1.1\r\n\r\n')
66+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
6767

6868
client.once('data', data => {
6969
t.match(data.toString(), /Connection:\s*keep-alive/i)
7070
t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
7171
t.match(data.toString(), /200 OK/i)
7272

73-
client.write('GET / HTTP/1.1\r\n\r\n')
73+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
7474

7575
client.once('data', data => {
7676
t.match(data.toString(), /Connection:\s*keep-alive/i)
7777
t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
7878
t.match(data.toString(), /200 OK/i)
7979

80-
client.write('GET / HTTP/1.1\r\n\r\n')
80+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
8181

8282
client.once('data', data => {
8383
t.match(data.toString(), /Connection:\s*keep-alive/i)

test/skip-reply-send.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) {
204204
app.listen({ port: 0 }, err => {
205205
t.error(err)
206206
const client = net.createConnection({ port: (app.server.address()).port }, () => {
207-
client.write('GET / HTTP/1.1\r\n\r\n')
207+
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
208208

209209
let chunks = ''
210210
client.setEncoding('utf8')

test/unsupported-httpversion.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ t.test('Will return 505 HTTP error if HTTP version (2.0 when server is 1.1) is n
1818

1919
const port = fastify.server.address().port
2020
const client = net.createConnection({ port }, () => {
21-
client.write('GET / HTTP/2.0\r\n\r\n')
21+
client.write('GET / HTTP/2.0\r\nHost: example.com\r\n\r\n')
2222

2323
client.once('data', data => {
2424
t.match(data.toString(), /505 HTTP Version Not Supported/i)

0 commit comments

Comments
 (0)