fixed CGI alloc

+ handle unknow status from script
This commit is contained in:
lperrey
2022-08-16 01:46:24 +02:00
parent e691c517e8
commit f8c6923c6d
5 changed files with 91 additions and 49 deletions

View File

@@ -122,9 +122,12 @@ void Webserv::_process_method(Client *client, std::string &path)
void Webserv::_insert_status_line(Client *client)
{
std::string status_line;
std::string status = _http_status[client->status];
if (status.empty())
status = ::itos(client->status);
status_line.append("HTTP/1.1 ");
status_line.append(_http_status[client->status]);
status_line.append(status);
status_line.append(CRLF);
client->response.insert(0, status_line);
}
@@ -141,8 +144,11 @@ void Webserv::_error_html_response(Client *client)
}
else
{
std::string status = _http_status[client->status];
if (status.empty())
status = "Error " + ::itos(client->status);
std::string html_page = HTML_ERROR;
::replace_all_substr(html_page, STATUS_PLACEHOLDER, _http_status[client->status]);
::replace_all_substr(html_page, STATUS_PLACEHOLDER, status);
_append_body(client, html_page, "html");
}
}