diff --git a/README.md b/README.md index 9643f38..12d13c5 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,6 @@ ## work together -#### next commit - -#### questions -- how should we handle a wrong url like `http://localhost/cgi-bin/wrong.phpp/good.php` ? - - do we serve `./srcs/cgi-bin/good.php` ? - - or do we return 404 "not found" ? --> - for now, execve would crash, but that doesn't produce a 404 error, rather a 500, is it bad ? - - could we use errno after execve to choose an appropriate http error ? subject says : "Checking the value of errno is strictly forbidden after a read or a write operation" -- if a url has a file with extension, but it's not a cgi extension, is it necessary to look further ? - - ex. `http://localhost/file.php/file.py` for `cgi_ext py;` ? -- the response page is received long after the cgi-script is done, why ? --- ## man diff --git a/srcs/Client.cpp b/srcs/Client.cpp index 06d0de5..493f8c2 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -220,11 +220,6 @@ void Client::fill_script_path(std::string &path, size_t pos) { std::string tmp; - if (path[0] == '.') - { - path.erase(0, 1); - pos--; - } _request.script.path = path.substr(0, pos); _request.script.info = path.substr(pos); } diff --git a/srcs/cgi-bin/Makefile b/srcs/cgi-bin/Makefile index 59f349c..24dfe80 100644 --- a/srcs/cgi-bin/Makefile +++ b/srcs/cgi-bin/Makefile @@ -1,3 +1,4 @@ + # - - - - - - # # # # COLORS # @@ -30,11 +31,7 @@ RESET = "\e[0m" # . name is case sensitive . ?= set if not already set # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -NAME_1 = $(SRCS_1:.cpp=.out) -NAME_2 = $(SRCS_2:.cpp=.out) -NAME_3 = $(SRCS_3:.cpp=.out) -NAME_4 = $(SRCS_4:.cpp=.out) -NAME_5 = $(SRCS_5:.cpp=.out) +NAME = $(SRCS_X:.cpp=.out) CXX = c++ CXXFLAGS = -Wall -Wextra #-Werror @@ -47,19 +44,23 @@ HEADERS_D = . SRCS_D = . SRCS = cgi_utils.cpp -SRCS_1 = cgi_cpp.cpp -SRCS_2 = cgi_cpp_len.cpp -SRCS_3 = cgi_cpp_len_big.cpp -SRCS_4 = cgi_cpp_len_small.cpp -SRCS_5 = cgi_cpp_status.cpp +SRCS_X = \ + cgi_cpp.cpp \ + cgi_cpp_bad_headers.cpp \ + cgi_cpp_empty.cpp \ + cgi_cpp_empty_lines.cpp \ + cgi_cpp_len.cpp \ + cgi_cpp_len_big.cpp \ + cgi_cpp_len_small.cpp \ + cgi_cpp_no_body.cpp \ + cgi_cpp_no_headers.cpp \ + cgi_cpp_only_crlf.cpp \ + cgi_cpp_sleep.cpp \ + cgi_cpp_status.cpp \ OBJS_D = builds OBJS = $(SRCS:%.cpp=$(OBJS_D)/%.o) -OBJS_1 = $(SRCS_1:%.cpp=$(OBJS_D)/%.o) -OBJS_2 = $(SRCS_2:%.cpp=$(OBJS_D)/%.o) -OBJS_3 = $(SRCS_3:%.cpp=$(OBJS_D)/%.o) -OBJS_4 = $(SRCS_4:%.cpp=$(OBJS_D)/%.o) -OBJS_5 = $(SRCS_5:%.cpp=$(OBJS_D)/%.o) +OBJS_X = $(SRCS_X:%.cpp=$(OBJS_D)/%.o) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # . target: prerequisites . $@ : target # @@ -67,36 +68,25 @@ OBJS_5 = $(SRCS_5:%.cpp=$(OBJS_D)/%.o) # . recipe . $^ : all prerequisites # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -all: cgi_1 cgi_2 cgi_3 cgi_4 cgi_5 -cgi_1: $(NAME_1) -cgi_2: $(NAME_2) -cgi_3: $(NAME_3) -cgi_4: $(NAME_4) -cgi_5: $(NAME_5) +all: $(NAME) $(OBJS_D)/%.o: %.cpp | $(OBJS_D) + @echo $(B_GREEN)"compilation :" $@ $(RESET) $(CXX) $(CXXFLAGS) -c $< -o $@ $(OBJS_D): mkdir $@ -$(NAME_1): $(OBJS) $(OBJS_1) -$(NAME_2): $(OBJS) $(OBJS_2) -$(NAME_3): $(OBJS) $(OBJS_3) -$(NAME_4): $(OBJS) $(OBJS_4) -$(NAME_5): $(OBJS) $(OBJS_5) -$(NAME_1) $(NAME_2) $(NAME_3) $(NAME_4) $(NAME_5): - $(CXX) $^ -o $@ +$(NAME): $(OBJS) $(OBJS_X) +$(NAME): + @echo $(B_YELLOW)"linkage :" $@ $(RESET) + $(CXX) $(OBJS) $(@:%.out=$(OBJS_D)/%.o) -o $@ clean: rm -rf $(OBJS_D) fclean: clean - rm -f $(NAME_1) - rm -f $(NAME_2) - rm -f $(NAME_3) - rm -f $(NAME_4) - rm -f $(NAME_5) + rm -f $(NAME) re: fclean all diff --git a/srcs/cgi-bin/cgi_cpp.cpp b/srcs/cgi-bin/cgi_cpp.cpp index ea66df3..0182dd1 100644 --- a/srcs/cgi-bin/cgi_cpp.cpp +++ b/srcs/cgi-bin/cgi_cpp.cpp @@ -3,13 +3,16 @@ int main (int ac, char **av, char ** env) { - std::string http_header; - std::string http_body; + std::string http_header; + std::string http_body; + std::string rq_body; + + std::cin >> rq_body; (void)ac; (void)av; - fill_response_basic(env, http_body, http_header); + fill_response_basic(env, http_body, http_header, rq_body); std::cout << http_header << CRLF CRLF << http_body; diff --git a/srcs/cgi-bin/cgi_cpp_bad_headers.cpp b/srcs/cgi-bin/cgi_cpp_bad_headers.cpp new file mode 100644 index 0000000..efe12ed --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_bad_headers.cpp @@ -0,0 +1,22 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + std::string http_status; + std::string rq_body; + + std::cin >> rq_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header, rq_body); + + std::cout << "Bad-Headers: wrong" << CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_empty.cpp b/srcs/cgi-bin/cgi_cpp_empty.cpp new file mode 100644 index 0000000..9ea9129 --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_empty.cpp @@ -0,0 +1,12 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + (void)ac; + (void)av; + (void)env; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_empty_lines.cpp b/srcs/cgi-bin/cgi_cpp_empty_lines.cpp new file mode 100644 index 0000000..14a1361 --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_empty_lines.cpp @@ -0,0 +1,21 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + std::string rq_body; + + std::cin >> rq_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header, rq_body); + + std::cout << http_header << CRLF CRLF CRLF CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_len.cpp b/srcs/cgi-bin/cgi_cpp_len.cpp index 566ae7d..30f5991 100644 --- a/srcs/cgi-bin/cgi_cpp_len.cpp +++ b/srcs/cgi-bin/cgi_cpp_len.cpp @@ -5,11 +5,14 @@ int main (int ac, char **av, char ** env) { std::string http_header; std::string http_body; + std::string rq_body; + + std::cin >> rq_body; (void)ac; (void)av; - fill_response_basic(env, http_body, http_header); + fill_response_basic(env, http_body, http_header, rq_body); http_header += "Content-Length: " + itos(http_body.size()); diff --git a/srcs/cgi-bin/cgi_cpp_len_big.cpp b/srcs/cgi-bin/cgi_cpp_len_big.cpp index 4d8025e..3b6e330 100644 --- a/srcs/cgi-bin/cgi_cpp_len_big.cpp +++ b/srcs/cgi-bin/cgi_cpp_len_big.cpp @@ -3,13 +3,16 @@ int main (int ac, char **av, char ** env) { - std::string http_header; - std::string http_body; + std::string http_header; + std::string http_body; + std::string rq_body; + + std::cin >> rq_body; (void)ac; (void)av; - fill_response_basic(env, http_body, http_header); + fill_response_basic(env, http_body, http_header, rq_body); http_header += "Content-Length: " + itos(http_body.size() + 100); diff --git a/srcs/cgi-bin/cgi_cpp_len_small.cpp b/srcs/cgi-bin/cgi_cpp_len_small.cpp index 4c58df9..98372e4 100644 --- a/srcs/cgi-bin/cgi_cpp_len_small.cpp +++ b/srcs/cgi-bin/cgi_cpp_len_small.cpp @@ -3,13 +3,16 @@ int main (int ac, char **av, char ** env) { - std::string http_header; - std::string http_body; + std::string http_header; + std::string http_body; + std::string rq_body; + + std::cin >> rq_body; (void)ac; (void)av; - fill_response_basic(env, http_body, http_header); + fill_response_basic(env, http_body, http_header, rq_body); http_header += "Content-Length: " + itos(http_body.size() - 100); diff --git a/srcs/cgi-bin/cgi_cpp_no_body.cpp b/srcs/cgi-bin/cgi_cpp_no_body.cpp new file mode 100644 index 0000000..70c57f5 --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_no_body.cpp @@ -0,0 +1,22 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + std::string http_status; + std::string rq_body; + + std::cin >> rq_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header, rq_body); + + std::cout << http_header << CRLF CRLF; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_no_headers.cpp b/srcs/cgi-bin/cgi_cpp_no_headers.cpp new file mode 100644 index 0000000..beb591d --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_no_headers.cpp @@ -0,0 +1,22 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + std::string http_status; + std::string rq_body; + + std::cin >> rq_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header, rq_body); + + std::cout << CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_only_crlf.cpp b/srcs/cgi-bin/cgi_cpp_only_crlf.cpp new file mode 100644 index 0000000..0c253b3 --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_only_crlf.cpp @@ -0,0 +1,15 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + (void)ac; + (void)av; + (void)env; + + std::cout << CRLF CRLF; + + return 0; +} + + diff --git a/srcs/cgi-bin/cgi_cpp_sleep.cpp b/srcs/cgi-bin/cgi_cpp_sleep.cpp new file mode 100644 index 0000000..303c074 --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_sleep.cpp @@ -0,0 +1,23 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + std::string rq_body; + + std::cin >> rq_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header, rq_body); + + sleep(60); + + std::cout << http_header << CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_status.cpp b/srcs/cgi-bin/cgi_cpp_status.cpp index 7fc2715..bbcf103 100644 --- a/srcs/cgi-bin/cgi_cpp_status.cpp +++ b/srcs/cgi-bin/cgi_cpp_status.cpp @@ -6,13 +6,16 @@ int main (int ac, char **av, char ** env) std::string http_header; std::string http_body; std::string http_status; + std::string rq_body; + + std::cin >> rq_body; (void)ac; (void)av; - fill_response_basic(env, http_body, http_header); + fill_response_basic(env, http_body, http_header, rq_body); - http_status = get_value("Status"); + http_status = get_value("Status", rq_body); http_header += "Status: " + http_status; std::cout << http_header << CRLF CRLF << http_body; diff --git a/srcs/cgi-bin/cgi_utils.cpp b/srcs/cgi-bin/cgi_utils.cpp index 3be41e3..128ab99 100644 --- a/srcs/cgi-bin/cgi_utils.cpp +++ b/srcs/cgi-bin/cgi_utils.cpp @@ -69,14 +69,6 @@ std::string parse_env(const std::string & env) return ret; } -std::string parse_body() -{ - std::string ret; - - std::cin >> ret; - return ret; -} - std::string print_env(char **env, std::string tag) { std::string ret = ""; @@ -114,7 +106,7 @@ std::string return ret; } -std::string get_form_infos() +std::string get_form_infos(const std::string & rq_body) { std::string form_infos; std::string method; @@ -122,14 +114,14 @@ std::string get_form_infos() method = parse_env("REQUEST_METHOD"); if (method == "POST") - form_infos = parse_body(); + form_infos = rq_body; else if (method == "GET") form_infos = parse_env("QUERY_STRING"); return form_infos; } -std::string get_value(std::string key) +std::string get_value(const std::string & key, const std::string & rq_body) { std::string infos; std::string ret; @@ -137,7 +129,7 @@ std::string get_value(std::string key) size_t end; size_t len; - infos = get_form_infos(); + infos = get_form_infos(rq_body); pos = str_tolower(infos).find(str_tolower(key)); if (pos == NPOS) return ""; @@ -155,15 +147,17 @@ std::string get_value(std::string key) } void - fill_response_basic(char **env, std::string & http_body, std::string & http_header) + fill_response_basic( + char **env, + std::string & http_body, + std::string & http_header, + const std::string & rq_body) { std::string rq_method = "not found"; - std::string rq_body; std::string rq_query; std::string form_infos; rq_method = parse_env("REQUEST_METHOD"); - rq_body = parse_body(); rq_query = parse_env("QUERY_STRING"); if (rq_method == "POST") diff --git a/srcs/cgi-bin/cgi_utils.hpp b/srcs/cgi-bin/cgi_utils.hpp index 38446de..1d15391 100644 --- a/srcs/cgi-bin/cgi_utils.hpp +++ b/srcs/cgi-bin/cgi_utils.hpp @@ -8,6 +8,7 @@ # include # include // getenv # include // transform +# include // sleep # define CR "\r" # define LF "\n" @@ -24,42 +25,44 @@ " "\ " "\ " "\ - "

cgi


" -# define HTML_BODY_BOTTOM " "\ + "

CGI


" +# define HTML_BODY_BOTTOM "

END CGI

"\ + " "\ "" std::string - str_tolower(std::string str); +str_tolower(std::string str); std::string - trim(std::string str, char del); +trim(std::string str, char del); std::vector - split(const std::string & input, std::string delim, char ctrim = '\0'); +split(const std::string & input, std::string delim, char ctrim = '\0'); std::string - itos(int n); +itos(int n); std::string - parse_env(const std::string & env); +parse_env(const std::string & env); std::string - parse_body(); +print_env(char **env, std::string tag = "p"); std::string - print_env(char **env, std::string tag = "p"); +get_form_infos(const std::string & rq_body); std::string - get_form_infos(); +get_value(const std::string & key, const std::string & rq_body); std::string - get_value(std::string key); - -std::string - print_form(std::string form, std::string key = "p", std::string val = "p"); +print_form(std::string form, std::string key = "p", std::string val = "p"); void - fill_response_basic(char **env, std::string & body, std::string & header); +fill_response_basic( + char **env, + std::string & http_body, + std::string & http_header, + const std::string & rq_body); #endif diff --git a/srcs/webserv/Webserv.hpp b/srcs/webserv/Webserv.hpp index 0be5e74..158fabc 100644 --- a/srcs/webserv/Webserv.hpp +++ b/srcs/webserv/Webserv.hpp @@ -129,10 +129,12 @@ class Webserv std::string _exec_script(Client *client, char *env[]); void _check_script_output(Client *client, std::string & output); void _check_script_status(Client *client, std::string & output); - void _check_script_fields(Client *client, std::string & output); + size_t _check_script_fields(const std::string & output, size_t status); + void _check_fields_duplicates(Client *client, std::string & output); void _add_script_body_length_header(std::string & output); void _remove_body_leading_empty_lines(std::string & output); + /////////////////////// class ExecFail : public std::exception { diff --git a/srcs/webserv/cgi.cpp b/srcs/webserv/cgi.cpp index 056d038..b79b139 100644 --- a/srcs/webserv/cgi.cpp +++ b/srcs/webserv/cgi.cpp @@ -18,7 +18,7 @@ bool Webserv::_is_cgi(Client *client, std::string path) if (pos == NPOS) break; client->fill_script_path(path, pos); - script_path = "." + client->get_rq_script_path(); + script_path = client->get_rq_script_path(); file_type = ::eval_file_type(script_path); if (file_type == IS_DIR) // but what if it's a symlink ? continue; @@ -128,7 +128,7 @@ void Webserv::_set_env_vector(Client *client, std::vector &env_vect env_vector.push_back(_dup_env("REMOTE_IDENT")); // authentification not supported env_vector.push_back(_dup_env("REMOTE_USER")); // authentification not supported env_vector.push_back(_dup_env("REQUEST_METHOD" , client->get_rq_method_str())); - env_vector.push_back(_dup_env("SCRIPT_NAME" , client->get_rq_script_path())); // LUKE: To Check + env_vector.push_back(_dup_env("SCRIPT_NAME" , "/" + client->get_rq_script_path())); // LUKE: To Check env_vector.push_back(_dup_env("SERVER_NAME" , client->get_cl_lsocket()->host)); env_vector.push_back(_dup_env("SERVER_PORT" , client->get_cl_lsocket()->port)); env_vector.push_back(_dup_env("SERVER_PROTOCOL" , "HTTP/1.1")); @@ -228,7 +228,7 @@ std::string Webserv::_exec_script(Client *client, char *env[]) ::close(FD_RD_FR_PRNT); ::close(FD_WR_TO_PRNT); - path = "." + client->get_rq_script_path(); // Wut ? Only relative path ? + path = client->get_rq_script_path(); // Wut ? Only relative path ? /*DEBUG*/std::cerr << "execve:[" << path << "]\n"; if (execve(path.c_str(), nll, env) == -1) // replace path for debug error forcing { @@ -278,16 +278,14 @@ void Webserv::_check_script_output(Client *client, std::string & output) _check_script_status(client, output); if (client->status >= 400 && client->status < 600) return; -///*DEBUG*/ std::cout << "\n" B_PURPLE "[script status]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; - _check_script_fields(client, output); -///*DEBUG*/ std::cout << "\n" B_PURPLE "[script fields]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; +//*DEBUG*/ std::cout << "\n" B_PURPLE "[script status]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; + client->status = _check_script_fields(output, client->status); + _check_fields_duplicates(client, output); +//*DEBUG*/ std::cout << "\n" B_PURPLE "[script fields]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; _remove_body_leading_empty_lines(output); -///*DEBUG*/ std::cout << "\n" B_PURPLE "[script empty lines]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; +//*DEBUG*/ std::cout << "\n" B_PURPLE "[script empty lines]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; _add_script_body_length_header(output); -///*DEBUG*/ std::cout << "\n" B_PURPLE "[script content length]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; - // _check_script_empty_lines(client, output); - // _check_script_space_colons(client, output); - // _check_script_new_lines(client, output); +//*DEBUG*/ std::cout << "\n" B_PURPLE "[script content length]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n"; } void Webserv::_check_script_status(Client *client, std::string & output) @@ -306,7 +304,35 @@ void Webserv::_check_script_status(Client *client, std::string & output) client->status = 200; } -void Webserv::_check_script_fields(Client *client, std::string & output) +size_t Webserv::_check_script_fields(const std::string & output, size_t status) +{ + std::string headers; + std::string body; + size_t pos; + + pos = output.find(CRLF CRLF); + if (pos == NPOS) // there is not empty line + return 500; + headers = output.substr(0, pos); + body = output.substr(pos + CRLF_SIZE * 2); + headers = str_tolower(headers); + pos = headers.find("content-type"); + if (pos == NPOS) // there is no content-type field + { + if (!body.empty()) // there is body + return 500; + if (headers.find("location") == NPOS) // there is no location field + return 500; + } + else if (headers.find("location") != NPOS) // there is a location field + { + if (body.empty()) // there is no body + return 500; + } + return status; +} + +void Webserv::_check_fields_duplicates(Client *client, std::string & output) { std::map srv_fld; // server_field std::map scr_fld; // script_field diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 9e8357e..253be0c 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -47,7 +47,7 @@ int Webserv::_send_response(Client *client) if (client->status >= 400) _error_html_response(client); -//*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output + headers]:" RESET "\n"; ::print_special(client->response); std::cout << "\n" B_PURPLE "-----------" RESET "\n\n"; +/*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output + headers]:" RESET "\n"; ::print_special(client->response); std::cout << "\n" B_PURPLE "-----------" RESET "\n\n"; std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0); @@ -86,16 +86,17 @@ void Webserv::_construct_response(Client *client) std::string path; std::string script_output; +/*DEBUG*/ std::cout << "\n" B_PURPLE "[responseeeeeeeeeeeeee]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; path = _replace_url_root(client, client->get_rq_abs_path()); if (_is_cgi(client, path)) { script_output = _exec_cgi(client); -//*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; -//*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(script_output); std::cout << B_PURPLE "-----------" RESET "\n\n"; +/*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; +/*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(script_output); std::cout << B_PURPLE "-----------" RESET "\n\n"; _check_script_output(client, script_output); if (client->status < 400) client->response += script_output; -//*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; +/*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; return; } diff --git a/www/form_cgi.html b/www/form_cgi.html index 4dd1d8b..500961a 100644 --- a/www/form_cgi.html +++ b/www/form_cgi.html @@ -18,7 +18,6 @@ form { display: flex; flex-direction: column; - border: 1px solid red; margin: 20px; padding: 5px; } @@ -29,10 +28,31 @@ mark { margin: 0px 3px; } + #get form { + border: 1px solid red; + } + #post form { + border: 1px solid green; + } + +

get form

@@ -42,6 +62,8 @@


+

expectation:

+

normal output


@@ -53,6 +75,8 @@


+

expectation:

+

normal output


@@ -64,6 +88,8 @@


+

expectation:

+

normal output


@@ -75,6 +101,8 @@


+

expectation:

+

normal output


@@ -151,6 +179,100 @@ +

expectation:

+

depend on status code

+ +
+ +
+

get form

+

to /cgi-bin/cgi_cpp_empty_lines.out

+
+
+
+

+ +

expectation:

+

normal output

+
+
+ +
+

get form

+

to /cgi-bin/cgi_cpp_sleep.out

+
+
+
+

+ +

expectation:

+

the request will sleep for one minute

+

but other request chould not be blocked

+
+
+ +
+

get form

+

to /cgi-bin/cgi_cpp_no_body.out

+
+
+
+

+ +

expectation:

+

blank page

+
+
+ +
+

get form

+

to /cgi-bin/cgi_cpp_bad_headers.out

+
+
+
+

+ +

expectation:

+

error 500

+
+
+ +
+

get form

+

to /cgi-bin/cgi_cpp_empty.out

+
+
+
+

+ +

expectation:

+

error 500

+
+
+ +
+

get form

+

to /cgi-bin/cgi_cpp_no_headers.out

+
+
+
+

+ +

expectation:

+

error 500

+
+
+ +
+

get form

+

to /cgi-bin/cgi_cpp_only_crlf.out

+
+
+
+

+ +

expectation:

+

error 500

@@ -163,6 +285,8 @@


+

expectation:

+

normal output


@@ -174,6 +298,8 @@


+

expectation:

+

normal output


@@ -185,6 +311,8 @@


+

expectation:

+

normal output


@@ -196,6 +324,8 @@


+

expectation:

+

normal output


@@ -272,6 +402,100 @@ +

expectation:

+

depend on status code

+ +
+ +
+

post form

+

to /cgi-bin/cgi_cpp_empty_lines.out

+
+
+
+

+ +

expectation:

+

normal output

+
+
+ +
+

post form

+

to /cgi-bin/cgi_cpp_sleep.out

+
+
+
+

+ +

expectation:

+

the request will sleep for one minute

+

but other request chould not be blocked

+
+
+ +
+

post form

+

to /cgi-bin/cgi_cpp_no_body.out

+
+
+
+

+ +

expectation:

+

blank page

+
+
+ +
+

post form

+

to /cgi-bin/cgi_cpp_bad_headers.out

+
+
+
+

+ +

expectation:

+

error 500

+
+
+ +
+

post form

+

to /cgi-bin/cgi_cpp_empty.out

+
+
+
+

+ +

expectation:

+

error 500

+
+
+ +
+

post form

+

to /cgi-bin/cgi_cpp_no_headers.out

+
+
+
+

+ +

expectation:

+

error 500

+
+
+ +
+

post form

+

to /cgi-bin/cgi_cpp_only_crlf.out

+
+
+
+

+ +

expectation:

+

error 500