All files / core/blong-gogo/src rawBody.ts

100% Statements 27/27
100% Branches 2/2
100% Functions 1/1
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 281x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 4x 4x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import type {FastifyInstance} from 'fastify';
 
/**
 * Accept a body no parser understands, handing the handler the request stream.
 *
 * Fastify answers `415` for a content type nobody parses, so a route that receives bytes needs a
 * parser for them. The gateway calls this **inside an encapsulated context** and mounts only the route
 * that asked for it there (`rawBody: true` on the declaration) — a parser added to the instance itself
 * would make every route of the process accept content types it cannot read (`@@D-860`). `RestFs`
 * adds the same parser for its own routes.
 */
export function registerRawBody(server: FastifyInstance): void {
    server.addContentTypeParser('*', (_request, payload, done) => {
        done(null, payload);
    });
}
 
/**
 * Refuse a stream once it passes `max` bytes.
 *
 * The implementation moved to the package a realm may import: the handler that reads a raw body is the
 * one that must count it, and a realm importing this file failed to load in a deployment where the
 * runtime is a binary rather than a dependency — `Cannot find package '@feasibleone/blong-gogo'`
 * stopped the suite's migration Job and the pods beside it (`@@F-750`). One implementation, re-exported
 * here so the runtime's own callers and its test keep their import.
 */
export {limitBytes} from '@feasibleone/blong/stream';