From c2250633618543648d385cff8fb446dae18b715b Mon Sep 17 00:00:00 2001 From: hugogogo Date: Fri, 12 Aug 2022 11:45:06 +0200 Subject: [PATCH] script output fields is checked for duplicate --- Makefile | 2 +- srcs/Client.cpp | 1 + srcs/utils.cpp | 20 +++++++++++++++++++- srcs/utils.hpp | 1 + srcs/webserv/cgi_script.cpp | 3 --- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b8b6734..dd6deaf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ NAME = webserv -CXX = c++ +CXX = clang++ CXXFLAGS = -Wall -Wextra #-Werror CXXFLAGS += $(HEADERS_D:%=-I%) diff --git a/srcs/Client.cpp b/srcs/Client.cpp index 94259af..0dd22b3 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -284,6 +284,7 @@ void Client::_parse_request_fields() std::cerr << "err _parse_request_fields(): " << ret << " fields are bad formated\n"; status = 400; // "bad request" } + ::str_map_key_tolower(_request.headers); } void Client::_parse_port_hostname(std::string host) diff --git a/srcs/utils.cpp b/srcs/utils.cpp index 832187c..a153684 100644 --- a/srcs/utils.cpp +++ b/srcs/utils.cpp @@ -267,7 +267,8 @@ size_t err++; continue; } - key = ::str_tolower(key); // to make "key" case_insensitive +// bad idea, in cgi we need to have the original value +// key = ::str_tolower(key); // to make "key" case_insensitive val = (*it).substr(pos + 1); val = ::trim(val, ' '); fields.insert( std::pair(key, val) ); @@ -275,6 +276,23 @@ size_t return err; } +void str_map_key_tolower(std::map & mp) +{ + std::map new_mp; + std::map::iterator it; + std::string key; + std::string value; + + for (it = mp.begin(); it != mp.end(); it++) + { + key = it->first; + value = it->second; + key = ::str_tolower(key); + new_mp.insert( std::pair(key, value) ); + } + mp.swap(new_mp); +} + // DEBUG void print_special(std::string str) { diff --git a/srcs/utils.hpp b/srcs/utils.hpp index 2a766d5..bb9fae4 100644 --- a/srcs/utils.hpp +++ b/srcs/utils.hpp @@ -51,6 +51,7 @@ 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 str_map_key_tolower(std::map & mp); void throw_test(); // debug void print_special(std::string str); diff --git a/srcs/webserv/cgi_script.cpp b/srcs/webserv/cgi_script.cpp index d15b391..45b333b 100644 --- a/srcs/webserv/cgi_script.cpp +++ b/srcs/webserv/cgi_script.cpp @@ -198,9 +198,6 @@ for (it = scr_fld.begin(); it != scr_fld.end(); it++) { { pos = client->response.find(it_srv->first); ::extract_line(client->response, pos, CRLF); - // debug - std::cout << "helloooooooooooooooooooooooooooooo\n"; - std::cout << pos << "\n"; } } }