<commit_before>#include "request.h"
#include "session_plain.h"
#include <regex>

namespace httpserver {

void dynamic_request::parse_query()
{
    std::string url = this->target().to_string();

    std::regex pattern("([\\w+%]+)=([^&#]*)");
    auto words_begin = std::sregex_iterator(url.begin(), url.end(), pattern);
    auto words_end = std::sregex_iterator();

    for (std::sregex_iterator i = words_begin; i != words_end; i++)
    {
        std::string key = (*i)[1].str();
        std::string value = (*i)[2].str();
        query_[key] = value;
    }
}

dynamic_request::dynamic_request()  {
    this->request_parser_ = nullptr;
}

dynamic_request::dynamic_request(request_parser_empty* req_empty, session* session) :
    request_empty(req_empty->get()) {
    this->request_parser_ = req_empty;
    session_ = session;
}<commit_msg>decoder url query<commit_after>#include "request.h"
#include "session_plain.h"
#include <regex>

namespace httpserver {

std::string urlDecode(std::string &eString) {
    std::string ret;
    char ch;
    int i, j;
    for (i=0; i<eString.length(); i++) {
        if (int(eString[i])==37) {
            sscanf(eString.substr(i+1,2).c_str(), "%x", &j);
            ch=static_cast<char>(j);
            ret+=ch;
            i=i+2;
        } else {
            ret+=eString[i];
        }
    }
    return (ret);
}

void dynamic_request::parse_query()
{
    std::string url = this->target().to_string();

    std::regex pattern("([\\w+%]+)=([^&#]*)");
    auto words_begin = std::sregex_iterator(url.begin(), url.end(), pattern);
    auto words_end = std::sregex_iterator();

    for (std::sregex_iterator i = words_begin; i != words_end; i++)
    {
        std::string key = (*i)[1].str();
        std::string value = (*i)[2].str();
        query_[key] = urlDecode( value );
    }
}

dynamic_request::dynamic_request()  {
    this->request_parser_ = nullptr;
}

dynamic_request::dynamic_request(request_parser_empty* req_empty, session* session) :
    request_empty(req_empty->get()) {
    this->request_parser_ = req_empty;
    session_ = session;
}
{'fraction_non_alphanumeric': 0.18168744007670182, 'fraction_numerical': 0.004793863854266539, 'mean_word_length': 3.468950749464668, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '78895', 'n_tokens_mistral': 715, 'n_tokens_neox': 705, 'n_words': 129}