<commit_before>/*
     This file is part of libhttpserver
     Copyright (C) 2011-2019 <NAME>

     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
     version 2.1 of the License, or (at your option) any later version.

     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Lesser General Public License for more details.

     You should have received a copy of the GNU Lesser General Public
     License along with this library; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
     USA
*/

#if !defined (_HTTPSERVER_HPP_INSIDE_) && !defined (HTTPSERVER_COMPILATION)
#error "Only <httpserver.hpp> or <httpserverpp> can be included directly."
#endif

#ifndef SRC_HTTPSERVER_HTTP_REQUEST_HPP_
#define SRC_HTTPSERVER_HTTP_REQUEST_HPP_

#include <microhttpd.h>

#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
#endif  // HAVE_GNUTLS

#include <stddef.h>
#include <algorithm>
#include <iosfwd>
#include <map>
#include <string>
#include <utility>
#include <vector>

#include "httpserver/http_utils.hpp"
#include "httpserver/file_info.hpp"

struct MHD_Connection;

namespace httpserver {

/**
 * Class representing an abstraction for an Http Request. It is used from classes using these apis to receive information through http protocol.
**/
class http_request {
 public:
     static const char EMPTY[];

     /**
      * Method used to get the username eventually passed through basic authentication.
      * @return string representation of the username.
     **/
     const std::string get_user() const;

     /**
      * Method used to get the username extracted from a digest authentication
      * @return the username
     **/
     const std::string get_digested_user() const;

     /**
      * Method used to get the password eventually passed through basic authentication.
      * @return string representation of the password.
     **/
     const std::string get_pass() const;

     /**
      * Method used to get the path requested
      * @return string representing the path requested.
     **/
     const std::string& get_path() const {
         return path;
     }

     /**
      * Method used to get all pieces of the path requested; considering an url splitted by '/'.
      * @return a vector of strings containing all pieces
     **/
     const std::vector<std::string> get_path_pieces() const {
         return http::http_utils::tokenize_url(path);
     }

     /**
      * Method used to obtain a specified piece of the path; considering an url splitted by '/'.
      * @param index the index of the piece selected
      * @return the selected piece in form of string
     **/
     const std::string get_path_piece(int index) const {
         std::vector<std::string> post_path = get_path_pieces();
         if ((static_cast<int>((post_path.size()))) > index) {
             return post_path[index];
         }
         return EMPTY;
     }

     /**
      * Method used to get the METHOD used to make the request.
      * @return string representing the method.
     **/
     const std::string& get_method() const {
         return method;
     }

     /**
      * Method used to get all headers passed with the request.
      * @param result a map<string, string> > that will be filled with all headers
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::header_comparator> get_headers() const;

     /**
      * Method used to get all footers passed with the request.
      * @param result a map<string, string> > that will be filled with all footers
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::header_comparator> get_footers() const;

     /**
      * Method used to get all cookies passed with the request.
      * @param result a map<string, string> > that will be filled with all cookies
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::header_comparator> get_cookies() const;

     /**
      * Method used to get all args passed with the request.
      * @param result a map<string, string> > that will be filled with all args
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::arg_comparator> get_args() const;

     /**
      * Method to get or create a file info struct in the map if the provided filename is already in the map
      * return the exiting file info struct, otherwise create one in the map and return it.
      * @param upload_file_name the file name the user uploaded (this is the identifier for the map entry)
      * @result a file info struct file_info_s
     **/
     http::file_info& get_or_create_file_info(const std::string& key, const std::string& upload_file_name);

     /**
      * Method used to get all files passed with the request.
      * @result result a map<string, file_info_s> > that will be filled with all files
     **/
     const std::map<std::string, std::map<std::string, http::file_info>> get_files() const {
          return files;
     }

     /**
      * Method used to get a specific header passed with the request.<commit_msg>Minor changes to doc annotations<commit_after>/*
     This file is part of libhttpserver
     Copyright (C) 2011-2019 <NAME>

     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
     version 2.1 of the License, or (at your option) any later version.

     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Lesser General Public License for more details.

     You should have received a copy of the GNU Lesser General Public
     License along with this library; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
     USA
*/

#if !defined (_HTTPSERVER_HPP_INSIDE_) && !defined (HTTPSERVER_COMPILATION)
#error "Only <httpserver.hpp> or <httpserverpp> can be included directly."
#endif

#ifndef SRC_HTTPSERVER_HTTP_REQUEST_HPP_
#define SRC_HTTPSERVER_HTTP_REQUEST_HPP_

#include <microhttpd.h>

#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
#endif  // HAVE_GNUTLS

#include <stddef.h>
#include <algorithm>
#include <iosfwd>
#include <map>
#include <string>
#include <utility>
#include <vector>

#include "httpserver/http_utils.hpp"
#include "httpserver/file_info.hpp"

struct MHD_Connection;

namespace httpserver {

/**
 * Class representing an abstraction for an Http Request. It is used from classes using these apis to receive information through http protocol.
**/
class http_request {
 public:
     static const char EMPTY[];

     /**
      * Method used to get the username eventually passed through basic authentication.
      * @return string representation of the username.
     **/
     const std::string get_user() const;

     /**
      * Method used to get the username extracted from a digest authentication
      * @return the username
     **/
     const std::string get_digested_user() const;

     /**
      * Method used to get the password eventually passed through basic authentication.
      * @return string representation of the password.
     **/
     const std::string get_pass() const;

     /**
      * Method used to get the path requested
      * @return string representing the path requested.
     **/
     const std::string& get_path() const {
         return path;
     }

     /**
      * Method used to get all pieces of the path requested; considering an url splitted by '/'.
      * @return a vector of strings containing all pieces
     **/
     const std::vector<std::string> get_path_pieces() const {
         return http::http_utils::tokenize_url(path);
     }

     /**
      * Method used to obtain a specified piece of the path; considering an url splitted by '/'.
      * @param index the index of the piece selected
      * @return the selected piece in form of string
     **/
     const std::string get_path_piece(int index) const {
         std::vector<std::string> post_path = get_path_pieces();
         if ((static_cast<int>((post_path.size()))) > index) {
             return post_path[index];
         }
         return EMPTY;
     }

     /**
      * Method used to get the METHOD used to make the request.
      * @return string representing the method.
     **/
     const std::string& get_method() const {
         return method;
     }

     /**
      * Method used to get all headers passed with the request.
      * @param result a map<string, string> > that will be filled with all headers
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::header_comparator> get_headers() const;

     /**
      * Method used to get all footers passed with the request.
      * @param result a map<string, string> > that will be filled with all footers
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::header_comparator> get_footers() const;

     /**
      * Method used to get all cookies passed with the request.
      * @param result a map<string, string> > that will be filled with all cookies
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::header_comparator> get_cookies() const;

     /**
      * Method used to get all args passed with the request.
      * @param result a map<string, string> > that will be filled with all args
      * @result the size of the map
     **/
     const std::map<std::string, std::string, http::arg_comparator> get_args() const;

     /**
      * Method to get or create a file info struct in the map if the provided filename is already in the map
      * return the exiting file info struct, otherwise create one in the map and return it.
      * @param upload_file_name the file name the user uploaded (this is the identifier for the map entry)
      * @result a http::file_info
     **/
     http::file_info& get_or_create_file_info(const std::string& key, const std::string& upload_file_name);

     /**
      * Method used to get all files passed with the request.
      * @result result a map<std::string, map<std::string, http::file_info> > that will be filled with all files
     **/
     const std::map<std::string, std::map<std::string, http::file_info>> get_files() const {
          return files;
     }

     /**
      * Method used to get a specific header passed with the request.
{'fraction_non_alphanumeric': 0.08745663684498813, 'fraction_numerical': 0.00383421581157568, 'mean_word_length': 2.894418769996445, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 67, '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': '1187360', 'n_tokens_mistral': 3035, 'n_tokens_neox': 2977, 'n_words': 1247}