Header names are automatically lower-cased now.

This commit is contained in:
Fred Nicolson 2017-04-11 10:39:23 +01:00
parent 561b395e93
commit 53ab6e2090
3 changed files with 8 additions and 7 deletions

View File

@ -155,7 +155,7 @@ namespace fr
* @param key The name of the header
* @return A reference to the header
*/
std::string &header(const std::string &key);
std::string &header(std::string &&key);
/*!

View File

@ -151,8 +151,9 @@ namespace fr
return result;
}
std::string &Http::header(const std::string &key)
std::string &Http::header(std::string &&key)
{
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return header_data[key];
}

View File

@ -45,15 +45,15 @@ namespace fr
//Add the headers to the response
for(const auto &header : header_data)
{
std::string data = header.first + ": " + url_encode(header.second) + "\r\n";
std::string data = header.first + ": " + header.second + "\r\n";
response += data;
}
//Add in required headers if they're missing
if(header_data.find("Connection") == header_data.end())
response += "Connection: close_socket\r\n";
if(header_data.find("Content-type") == header_data.end())
response += "Content-type: text/html\r\n";
if(header_data.find("connection") == header_data.end())
response += "connection: close_socket\r\n";
if(header_data.find("content-type") == header_data.end())
response += "content-type: text/html\r\n";
//Add in space
response += "\r\n";