request-header-host.test.js — fastify Source File
Architecture documentation for request-header-host.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const { test } = require('node:test')
const { connect } = require('node:net')
const Fastify = require('..')
// RFC9112
// https://www.rfc-editor.org/rfc/rfc9112
test('Return 400 when Host header is missing', (t, done) => {
t.plan(2)
let data = Buffer.alloc(0)
const fastify = Fastify()
t.after(() => fastify.close())
fastify.get('/', async function () {
t.assert.fail('should not reach handler')
return { ok: true }
})
fastify.listen({ port: 0 }, err => {
t.assert.ifError(err)
const socket = connect(fastify.server.address().port)
socket.write('GET / HTTP/1.1\r\n\r\n')
socket.on('data', c => (data = Buffer.concat([data, c])))
socket.on('end', () => {
t.assert.match(
data.toString('utf-8'),
/^HTTP\/1.1 400 Bad Request/
)
done()
})
})
})
test('Return 400 when Host header is missing with trust proxy', (t, done) => {
t.plan(2)
let data = Buffer.alloc(0)
const fastify = Fastify({
trustProxy: true
})
t.after(() => fastify.close())
fastify.get('/', async function () {
t.assert.fail('should not reach handler')
return { ok: true }
})
fastify.listen({ port: 0 }, err => {
t.assert.ifError(err)
const socket = connect(fastify.server.address().port)
socket.write('GET / HTTP/1.1\r\n\r\n')
socket.on('data', c => (data = Buffer.concat([data, c])))
socket.on('end', () => {
t.assert.match(
data.toString('utf-8'),
/^HTTP\/1.1 400 Bad Request/
)
done()
// ... (280 more lines)
Source
Frequently Asked Questions
What does request-header-host.test.js do?
request-header-host.test.js is a source file in the fastify codebase, written in javascript.
Where is request-header-host.test.js in the architecture?
request-header-host.test.js is located at test/request-header-host.test.js (directory: test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free