"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentLengthParser = void 0;
const global_logger_factory_1 = require("global-logger-factory");
const MetadataParser_1 = require("./MetadataParser");
/**
 * Parser for the `content-length` header.
 */
class ContentLengthParser extends MetadataParser_1.MetadataParser {
    logger = (0, global_logger_factory_1.getLoggerFor)(this);
    async handle(input) {
        const contentLength = input.request.headers['content-length'];
        if (contentLength) {
            const length = /^\s*(\d+)\s*(?:;.*)?$/u.exec(contentLength)?.[1];
            if (length) {
                input.metadata.contentLength = Number(length);
            }
            else {
                this.logger.warn(`Invalid content-length header found: ${contentLength}.`);
            }
        }
    }
}
exports.ContentLengthParser = ContentLengthParser;
//# sourceMappingURL=ContentLengthParser.js.map