Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to limit the size of request bodies for the default body p…
…arser
- Loading branch information
Showing
7 changed files
with
238 additions
and
14 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
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,46 @@ | ||
'use strict' | ||
|
||
const Fastify = require('..') | ||
const sget = require('simple-get').concat | ||
const t = require('tap') | ||
const test = t.test | ||
|
||
test('jsonBodyLimit option', t => { | ||
t.plan(5) | ||
|
||
try { | ||
Fastify({ jsonBodyLimit: 1.3 }) | ||
t.fail('option must be an integer') | ||
} catch (err) { | ||
t.ok(err) | ||
} | ||
|
||
try { | ||
Fastify({ jsonBodyLimit: [] }) | ||
t.fail('option must be an integer') | ||
} catch (err) { | ||
t.ok(err) | ||
} | ||
|
||
const fastify = Fastify({ jsonBodyLimit: 1 }) | ||
|
||
fastify.post('/', (request, reply) => { | ||
reply.send({error: 'handler should not be called'}) | ||
}) | ||
|
||
fastify.listen(0, function (err) { | ||
t.error(err) | ||
fastify.server.unref() | ||
|
||
sget({ | ||
method: 'POST', | ||
url: 'http://localhost:' + fastify.server.address().port, | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: [], | ||
json: true | ||
}, (err, response, body) => { | ||
t.error(err) | ||
t.strictEqual(response.statusCode, 413) | ||
}) | ||
}) | ||
}) |
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
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