wip cgi ouptput

This commit is contained in:
hugogogo
2022-08-15 16:18:47 +02:00
parent 036256522a
commit 6ad6ec7d63
4 changed files with 94 additions and 36 deletions

View File

@@ -1,40 +1,53 @@
# include "cgi_utils.hpp"
int main ()
int main (int ac, char **av, char ** env)
{
std::vector<std::string> split_str;
std::vector<std::string> sub_split_str;
std::vector<std::string>::const_iterator it;
std::string input;
std::string http_header;
std::string http_body;
std::string http_req_body;
std::string http_resp_header;
std::string http_resp_body;
std::cin >> input;
std::string tmp;
(void)ac;
(void)av;
(void)env;
http_body = HTML_BODY_TOP;
/*
rq_method = find_method();
rq_body = parse_body();
rq_query = parse_query();
http_body += fill_env("REQUEST_METHOD", "h3");
split_str = split(input, "&");
for (it = split_str.begin(); it != split_str.end(); ++it)
method used : GET
form query : key=val&key=val
form body : EMPTY
output :
first name: John
last name: Doe
cgi env variables :
CONTENT_TYPE: value
...
*/
tmp = "<p>PRINT ENV _________________</p>";
for (int i = 0; env[i] != NULL; ++i)
{
sub_split_str = split(*it, "=");
http_body += "<h3>";
http_body += sub_split_str[0];
http_body += "</h3>";
http_body += "<p>";
http_body += sub_split_str[1];
http_body += "</p>";
tmp += "<p>";
tmp += env[i];
tmp += "</p>";
}
tmp += "<p>___________________________</p>";
http_body += HTML_BODY_BOTTOM;
http_req_body = parse_form_infos();
http_header = "Content-Type: text/html; charset=UTF-8" CRLF;
http_header += "Content-Length: ";
http_header += itos(http_body.size());
http_resp_body = HTML_BODY_TOP;
http_resp_body += fill_tag("ENV:", "h3") + fill_env("REQUEST_METHOD");
http_resp_body += fill_form(http_req_body, "h3", "p");
http_resp_body += tmp;
http_resp_body += HTML_BODY_BOTTOM;
std::cout << http_header << CRLF CRLF << http_body;
http_resp_header = "Content-Type: text/html; charset=UTF-8" CRLF;
http_resp_header += "Content-Length: " + itos(http_resp_body.size());
std::cout << http_resp_header << CRLF CRLF << http_resp_body;
return 0;
}