Bug fixes
Fixed Content-Length header being added to Http responses even if there's a pre-existing one. Fixed header parsing sometimes adding a carriage return to the header value. Removed useless copy/move constructors from HttpResponse, causing issues.
This commit is contained in:
parent
df509a42f5
commit
93ec4fa999
@ -17,8 +17,6 @@ namespace fr
|
||||
public:
|
||||
//Constructors
|
||||
HttpResponse(){};
|
||||
HttpResponse(HttpResponse &&other);
|
||||
HttpResponse(const HttpResponse &);
|
||||
virtual ~HttpResponse(){}
|
||||
|
||||
/*!
|
||||
|
||||
28
src/Http.cpp
28
src/Http.cpp
@ -234,17 +234,27 @@ namespace fr
|
||||
|
||||
void Http::parse_header_line(const std::string &str)
|
||||
{
|
||||
auto colon_pos = str.find(":");
|
||||
if(colon_pos != std::string::npos)
|
||||
size_t colon_pos = str.find(':');
|
||||
if(colon_pos == std::string::npos)
|
||||
return;
|
||||
|
||||
auto data_begin = str.find_first_not_of(" ", colon_pos + 1);
|
||||
if(data_begin == std::string::npos)
|
||||
return;
|
||||
|
||||
size_t data_len = 0;
|
||||
for(size_t a = data_begin; a < str.size(); a++)
|
||||
{
|
||||
auto data_begin = str.find_first_not_of(" ", colon_pos + 1);
|
||||
if(data_begin != std::string::npos)
|
||||
{
|
||||
std::string header_name = str.substr(0, colon_pos);
|
||||
std::transform(header_name.begin(), header_name.end(), header_name.begin(), ::tolower);
|
||||
header_data.emplace(std::move(header_name), str.substr(data_begin, str.size() - data_begin));
|
||||
}
|
||||
if(str[a] >= 32 && str[a] <= 126)
|
||||
data_len++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
std::string header_name = str.substr(0, colon_pos);
|
||||
std::string header_value = str.substr(data_begin, data_len);
|
||||
|
||||
std::transform(header_name.begin(), header_name.end(), header_name.begin(), ::tolower);
|
||||
header_data.emplace(std::move(header_name), std::move(header_value));
|
||||
}
|
||||
|
||||
void Http::load_mimetypes()
|
||||
|
||||
@ -7,20 +7,6 @@
|
||||
|
||||
namespace fr
|
||||
{
|
||||
HttpResponse::HttpResponse(HttpResponse &&other)
|
||||
: header_ended(other.header_ended),
|
||||
content_length(other.content_length)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HttpResponse::HttpResponse(const HttpResponse &other)
|
||||
: header_ended(other.header_ended),
|
||||
content_length(other.content_length)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool HttpResponse::parse(const std::string &response_data)
|
||||
{
|
||||
body += response_data;
|
||||
@ -69,7 +55,8 @@ namespace fr
|
||||
response += "connection: close_socket\r\n";
|
||||
if(header_data.find("content-type") == header_data.end())
|
||||
response += "content-type: text/html\r\n";
|
||||
response += "content-length: " + std::to_string(body.size()) + "\r\n";
|
||||
if(header_data.find("content-length") == header_data.end())
|
||||
response += "content-length: " + std::to_string(body.size()) + "\r\n";
|
||||
|
||||
//Add in space
|
||||
response += "\r\n";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user