#ifndef UTILS_HPP # define UTILS_HPP # include # include # include # include # include // atoi # include // stat() # include // tolower # include // transform # include // fflush # define CR "\r" # define LF "\n" # define CRLF CR LF enum http_method { UNKNOWN = 0b0, GET = 1 << 0, POST = 1 << 1, DELETE = 1 << 2, ANY_METHODS = 0b11111111, // ALL_METHODS = 0b11111111, // i would prefer this... }; struct listen_socket { int fd; std::string host; std::string port; }; bool operator==(const listen_socket& lhs, int fd); bool operator==(int fd, const listen_socket& rhs); std::vector split(std::string input, char delimiter); std::vector split_trim(std::string input, std::string delim = "\n", char ctrim = '\0'); bool isNumeric(std::string str); bool isNumeric_btw(int low, int high, std::string str); std::string itos(int n); std::string trim(std::string str, char del); http_method str_to_http_method(std::string &str); std::string http_methods_to_str(unsigned int methods); int path_is_valid(std::string path); void replace_all_substr(std::string &str, const std::string &ori_substr, const std::string &new_substr); std::string str_tolower(std::string str); std::string extract_line(std::string & str, size_t pos = 0, std::string delim = "\n"); std::string get_line (std::string str, size_t pos = 0, std::string delim = "\n"); size_t parse_http_headers (std::string headers, std::map fields ); void throw_test(); // debug void print_special(std::string str); #endif