-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve error message if max allowed header size was exceeded
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const test = t.test | ||
const Fastify = require('..') | ||
const sget = require('simple-get').concat | ||
|
||
const maxHeaderSize = 1024 | ||
const expectedMessage = 'Exceeded maximum allowed HTTP header size' | ||
|
||
test('Should indicate in error message that header size was exceeded if URI is too long', t => { | ||
t.plan(4) | ||
|
||
const fastify = Fastify({ http: { maxHeaderSize } }) | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler: (_req, reply) => { | ||
reply.send({ hello: 'world' }) | ||
} | ||
}) | ||
|
||
fastify.listen({ port: 0 }, function (err) { | ||
t.error(err) | ||
|
||
sget({ | ||
method: 'GET', | ||
url: 'http://localhost:' + fastify.server.address().port + `/${'a'.repeat(maxHeaderSize)}` | ||
}, (err, res, body) => { | ||
t.error(err) | ||
t.equal(res.statusCode, 400) | ||
t.equal(JSON.parse(body).message, expectedMessage) | ||
}) | ||
}) | ||
|
||
t.teardown(() => fastify.close()) | ||
}) | ||
|
||
test('Should indicate in error message that header size was exceeded if request header fields are too large', t => { | ||
t.plan(4) | ||
|
||
const fastify = Fastify({ http: { maxHeaderSize } }) | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler: (_req, reply) => { | ||
reply.send({ hello: 'world' }) | ||
} | ||
}) | ||
|
||
fastify.listen({ port: 0 }, function (err) { | ||
t.error(err) | ||
|
||
sget({ | ||
method: 'GET', | ||
url: 'http://localhost:' + fastify.server.address().port, | ||
headers: { | ||
'Large-Header': 'a'.repeat(maxHeaderSize) | ||
} | ||
}, (err, res, body) => { | ||
t.error(err) | ||
t.equal(res.statusCode, 400) | ||
t.equal(JSON.parse(body).message, expectedMessage) | ||
}) | ||
}) | ||
|
||
t.teardown(() => { fastify.close() }) | ||
}) |