<commit_before>#include "pone.h"
#include "pone_module.h"
#include "../3rd/picohttpparser/picohttpparser.h"

PONE_FUNC(meth_parse_request) {
    pone_val* buf;

    PONE_ARG("http/parser.parse_request", "o", &buf);

    const char *method, *path;
    int minor_version;
    struct phr_header headers[100];
    size_t prevbuflen = 0, method_len, path_len;
    size_t num_headers = sizeof(headers) / sizeof(headers[0]);
    pone_dd(world, buf);

    int pret = phr_parse_request(
        pone_str_ptr(buf),
        pone_str_len(buf),
        &method, &method_len, &path, &path_len,
        &minor_version, headers, &num_headers, prevbuflen
    );
    if (pret > 0) {
        // TODO use list
        pone_val* env = pone_hash_new(world);
        pone_hash_assign_key_c(world, env, "REQUEST_METHOD", strlen("REQUEST_METHOD"),
                pone_str_new_strdup(world, method, method_len));
        pone_hash_assign_key_c(world, env, "REQUEST_URI", strlen("REQUEST_URI"),
                pone_str_new_strdup(world, path, path_len));<commit_msg>remove useless pone_dd<commit_after>#include "pone.h"
#include "pone_module.h"
#include "../3rd/picohttpparser/picohttpparser.h"

PONE_FUNC(meth_parse_request) {
    pone_val* buf;

    PONE_ARG("http/parser.parse_request", "o", &buf);

    const char *method, *path;
    int minor_version;
    struct phr_header headers[100];
    size_t prevbuflen = 0, method_len, path_len;
    size_t num_headers = sizeof(headers) / sizeof(headers[0]);

    int pret = phr_parse_request(
        pone_str_ptr(buf),
        pone_str_len(buf),
        &method, &method_len, &path, &path_len,
        &minor_version, headers, &num_headers, prevbuflen
    );
    if (pret > 0) {
        // TODO use list
        pone_val* env = pone_hash_new(world);
        pone_hash_assign_key_c(world, env, "REQUEST_METHOD", strlen("REQUEST_METHOD"),
                pone_str_new_strdup(world, method, method_len));
        pone_hash_assign_key_c(world, env, "REQUEST_URI", strlen("REQUEST_URI"),
                pone_str_new_strdup(world, path, path_len));
{'fraction_non_alphanumeric': 0.12391093901258471, 'fraction_numerical': 0.006776379477250726, 'mean_word_length': 3.445161290322581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2048885', 'n_tokens_mistral': 763, 'n_tokens_neox': 715, 'n_words': 135}