<commit_before>import { ProtonMiddleware } from "./ProtonMiddleware";
import { Middleware, MiddlewareFunctionParams } from "../decorators/MiddlewareConfig";

export class BodyParserMiddleware extends ProtonMiddleware {
    @Middleware()
    public bodyParser(params: MiddlewareFunctionParams): void {
        var data = '';
        params.req.setEncoding('utf8');
        params.req.on('data', (rawData) => data += rawData);

        params.req.on('end', () => {
            params.req.body = data;
            params.next();
        });
    }
}<commit_msg>Fixes BodyParserMiddleware for perform parse one time only<commit_after>import { ProtonMiddleware } from "./ProtonMiddleware";
import { Middleware, MiddlewareFunctionParams } from "../decorators/MiddlewareConfig";

export class BodyParserMiddleware extends ProtonMiddleware {
    @Middleware()
    public bodyParser(params: MiddlewareFunctionParams): void {
        if (params.req.body == undefined || params.req.body == null) {
            var data = '';
            params.req.setEncoding('utf8');
            params.req.on('data', (rawData) => data += rawData);

            params.req.on('end', () => {
                params.req.body = data;
                params.next();
            });
        } else {
            params.next();
        }
    }
}
{'fraction_non_alphanumeric': 0.13414634146341464, 'fraction_numerical': 0.001524390243902439, 'mean_word_length': 2.5582655826558267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3822472', 'n_tokens_mistral': 342, 'n_tokens_neox': 349, 'n_words': 74}