Home / File/ content-length.test.js — fastify Source File

content-length.test.js — fastify Source File

Architecture documentation for content-length.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const Fastify = require('..')

test('default 413 with bodyLimit option', async (t) => {
  t.plan(3)

  const fastify = Fastify({
    bodyLimit: 10
  })

  fastify.post('/', function (req, reply) {
    reply.send({ hello: 'world' })
  })

  const response = await fastify.inject({
    method: 'POST',
    url: '/',
    body: {
      text: '12345678901234567890123456789012345678901234567890'
    }
  })
  t.assert.strictEqual(response.statusCode, 413)
  t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
  t.assert.deepStrictEqual(JSON.parse(response.payload), {
    error: 'Payload Too Large',
    code: 'FST_ERR_CTP_BODY_TOO_LARGE',
    message: 'Request body is too large',
    statusCode: 413
  })
})

test('default 400 with wrong content-length', async (t) => {
  t.plan(3)

  const fastify = Fastify()

  fastify.post('/', function (req, reply) {
    reply.send({ hello: 'world' })
  })

  const response = await fastify.inject({
    method: 'POST',
    url: '/',
    headers: {
      'content-length': 20
    },
    body: {
      text: '12345678901234567890123456789012345678901234567890'
    }
  })
  t.assert.strictEqual(response.statusCode, 400)
  t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
  t.assert.deepStrictEqual(JSON.parse(response.payload), {
    error: 'Bad Request',
    code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
    message: 'Request body size did not match Content-Length',
    statusCode: 400
  })
// ... (115 more lines)

Frequently Asked Questions

What does content-length.test.js do?
content-length.test.js is a source file in the fastify codebase, written in javascript.
Where is content-length.test.js in the architecture?
content-length.test.js is located at test/content-length.test.js (directory: test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free