Skip to content

Commit

Permalink
fix: throw on keep-alive header (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored Jul 30, 2020
1 parent fea2fd6 commit be9fc08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class Parser extends HTTPParser {
const request = client[kQueue][client[kRunningIdx]]

// TODO: Check for content-length mismatch?
// TODO: keep-alive timeout & max?

assert(this.statusCode < 200)

Expand Down Expand Up @@ -815,6 +816,8 @@ function write (client, request) {
socket.write(`content-length: ${contentLength}\r\n`, 'ascii')
}

// TODO: keep-alive timeout=client[kSocketTimeout]?

if (method === 'HEAD') {
// https://github.com/mcollina/undici/issues/258

Expand Down
5 changes: 5 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class Request extends AsyncResource {
key.toLowerCase() === 'connection'
) {
throw new InvalidArgumentError('invalid connection header')
} else if (
key.length === 10 &&
key.toLowerCase() === 'keep-alive'
) {
throw new InvalidArgumentError('invalid keep-alive header')
} else {
header += `${key}: ${val}\r\n`
}
Expand Down
12 changes: 11 additions & 1 deletion test/invalid-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { test } = require('tap')
const { Client, errors } = require('..')

test('invalid headers', (t) => {
t.plan(5)
t.plan(6)

const client = new Client('http://localhost:3000')
t.teardown(client.destroy.bind(client))
Expand Down Expand Up @@ -38,6 +38,16 @@ test('invalid headers', (t) => {
t.ok(err instanceof errors.InvalidArgumentError)
})

client.request({
path: '/',
method: 'GET',
headers: {
'keep-alive': 'timeout=5'
}
}, (err, data) => {
t.ok(err instanceof errors.InvalidArgumentError)
})

client.request({
path: '/',
method: 'GET',
Expand Down

0 comments on commit be9fc08

Please sign in to comment.