wip cgi env variables

This commit is contained in:
hugogogo
2022-08-06 11:34:48 +02:00
parent 83536ee8ad
commit 6f171ec07b
6 changed files with 66 additions and 14 deletions

View File

@@ -43,16 +43,20 @@ void Client::parse_request()
list.erase(list.begin());
// headers
_parse_request_headers(list);
//body- message
// body-message
_parse_request_body(pos + 4);
// port and hostname
_parse_port_hostname(_request.headers["Host"]);
}
std::string Client::get_method() { return _request.method; }
std::string Client::get_path() { return _request.path; }
std::string Client::get_version() { return _request.version; }
std::string Client::get_body() { return _request.body; }
std::string Client::get_method() { return _request.method; }
std::string Client::get_path() { return _request.path; }
std::string Client::get_version() { return _request.version; }
std::string Client::get_body() { return _request.body; }
std::string Client::get_port() { return _request.port; }
std::string Client::get_hostname() { return _request.hostname; }
std::string Client::get_headers(std::string key) { return _request.headers[key]; }
/*********************************************
@@ -113,4 +117,25 @@ void Client::_parse_request_body( size_t pos )
_request.body = body;
}
void Client::_parse_port_hostname(std::string host)
{
size_t pos;
if (host == "")
{
std::cerr << "no host\n";
throw std::runtime_error("no host in request");
}
pos = host.find(':');
// port :
if (pos == std::string::npos)
_request.port = "4040"; // TODO: make equal to default port in config
else
_request.port = host.substr(pos);
if (_request.port == ":")
_request.port = "";
// hostname :
_request.hostname = host.substr(0, pos);
}