basic cgi script test working
This commit is contained in:
@@ -3,51 +3,49 @@
|
||||
|
||||
int main (int ac, char **av, char ** env)
|
||||
{
|
||||
std::string http_req_body;
|
||||
std::string http_resp_header;
|
||||
std::string http_resp_body;
|
||||
std::string rq_method = "not found";
|
||||
std::string rq_body = "";
|
||||
std::string rq_query = "";
|
||||
std::string form_infos = "";
|
||||
std::string http_header = "";
|
||||
std::string http_body = "";
|
||||
|
||||
std::string tmp;
|
||||
(void)ac;
|
||||
(void)av;
|
||||
(void)env;
|
||||
|
||||
/*
|
||||
rq_method = find_method();
|
||||
rq_body = parse_body();
|
||||
rq_query = parse_query();
|
||||
rq_method = parse_env("REQUEST_METHOD");
|
||||
rq_body = parse_body();
|
||||
rq_query = parse_env("QUERY_STRING");
|
||||
|
||||
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)
|
||||
{
|
||||
tmp += "<p>";
|
||||
tmp += env[i];
|
||||
tmp += "</p>";
|
||||
}
|
||||
tmp += "<p>___________________________</p>";
|
||||
if (rq_method == "POST")
|
||||
form_infos = rq_body;
|
||||
else if (rq_method == "GET")
|
||||
form_infos = rq_query;
|
||||
|
||||
http_req_body = parse_form_infos();
|
||||
http_body = HTML_BODY_TOP;
|
||||
|
||||
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;
|
||||
http_body += "<br><h3>method used: </h3>";
|
||||
http_body += "<p>" + rq_method + "</p>";
|
||||
|
||||
http_resp_header = "Content-Type: text/html; charset=UTF-8" CRLF;
|
||||
http_resp_header += "Content-Length: " + itos(http_resp_body.size());
|
||||
http_body += "<br><h3>form body: </h3>";
|
||||
http_body += "<p>" + rq_body + "</p>";
|
||||
|
||||
http_body += "<br><h3>form query: </h3>";
|
||||
http_body += "<p>" + rq_query + "</p>";
|
||||
|
||||
http_body += "<br><br><h3>output:</h3><br>";
|
||||
http_body += print_form(form_infos, "p", "p");
|
||||
|
||||
http_body += "<br><br><h3>cgi_env_variables:</h3><br>";
|
||||
http_body += print_env(env, "p");
|
||||
|
||||
http_body += HTML_BODY_BOTTOM;
|
||||
|
||||
http_header = "Content-Type: text/html; charset=UTF-8" CRLF;
|
||||
http_header += "Content-Length: " + itos(http_body.size() - 10);
|
||||
|
||||
std::cout << http_header << CRLF CRLF << http_body;
|
||||
|
||||
std::cout << http_resp_header << CRLF CRLF << http_resp_body;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user