async function readBody(req, typeInfo) {
    var _a, _b;
    const charset = (_b = (_a = typeInfo.parameters.charset) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'utf-8';
    // Assert charset encoding per JSON RFC 7159 sec 8.1
    if (!charset.startsWith('utf-')) {
        throw http_errors_1.default(415, `Unsupported charset "${charset.toUpperCase()}".`);
    }
    // Get content-encoding (e.g. gzip)
    const contentEncoding = req.headers['content-encoding'];
    const encoding = typeof contentEncoding === 'string'
        ? contentEncoding.toLowerCase()
        : 'identity';
    const length = encoding === 'identity' ? req.headers['content-length'] : null;
    const limit = 100 * 1024; // 100kb
    const stream = decompressed(req, encoding);
    // Read body from stream.
    try {
        return await raw_body_1.default(stream, { encoding: charset, length, limit });
    }
    catch (rawError) {
        const error = http_errors_1.default(400, 
        /* istanbul ignore next: Thrown by underlying library. */
        rawError instanceof Error ? rawError : String(rawError));
        error.message =
            error.type === 'encoding.unsupported'
                ? `Unsupported charset "${charset.toUpperCase()}".`
                : `Invalid body: ${error.message}.`;
        throw error;
    }
}
// Read and parse a request body.
Read and parse a request body.
Read and parse a request body .
async function readBody(req, typeInfo) {
    var _a, _b;
    const charset = (_b = (_a = typeInfo.parameters.charset) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'utf-8';
    if (!charset.startsWith('utf-')) {
        throw http_errors_1.default(415, `Unsupported charset "${charset.toUpperCase()}".`);
    }
    const contentEncoding = req.headers['content-encoding'];
    const encoding = typeof contentEncoding === 'string'
        ? contentEncoding.toLowerCase()
        : 'identity';
    const length = encoding === 'identity' ? req.headers['content-length'] : null;
    const limit = 100 * 1024; 
    const stream = decompressed(req, encoding);
    try {
        return await raw_body_1.default(stream, { encoding: charset, length, limit });
    }
    catch (rawError) {
        const error = http_errors_1.default(400, 
        rawError instanceof Error ? rawError : String(rawError));
        error.message =
            error.type === 'encoding.unsupported'
                ? `Unsupported charset "${charset.toUpperCase()}".`
                : `Invalid body: ${error.message}.`;
        throw error;
    }
}
async function readBody ( req , typeInfo ) { var _a , _b ; const charset = ( _b = ( _a = typeInfo . parameters . charset ) === null || _a === void 0 ? void 0 : _a . toLowerCase ( ) ) !== null && _b !== void 0 ? _b : 'utf-8' ; if ( ! charset . startsWith ( 'utf-' ) ) { throw http_errors_1 . default ( 415 , ` ${ charset . toUpperCase ( ) } ` ) ; } const contentEncoding = req . headers [ 'content-encoding' ] ; const encoding = typeof contentEncoding === 'string' ? contentEncoding . toLowerCase ( ) : 'identity' ; const length = encoding === 'identity' ? req . headers [ 'content-length' ] : null ; const limit = 100 * 1024 ; const stream = decompressed ( req , encoding ) ; try { return await raw_body_1 . default ( stream , { encoding : charset , length , limit } ) ; } catch ( rawError ) { const error = http_errors_1 . default ( 400 , rawError instanceof Error ? rawError : String ( rawError ) ) ; error . message = error . type === 'encoding.unsupported' ? ` ${ charset . toUpperCase ( ) } ` : ` ${ error . message } ` ; throw error ; } }
Read and parse a request body.
Read and parse a request body .
// Assert charset encoding per JSON RFC 7159 sec 8.1 // Get content-encoding (e.g. gzip) // 100kb // Read body from stream. /* istanbul ignore next: Thrown by underlying library. */