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:
|
public:
|
||||||
//Constructors
|
//Constructors
|
||||||
HttpResponse(){};
|
HttpResponse(){};
|
||||||
HttpResponse(HttpResponse &&other);
|
|
||||||
HttpResponse(const HttpResponse &);
|
|
||||||
virtual ~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)
|
void Http::parse_header_line(const std::string &str)
|
||||||
{
|
{
|
||||||
auto colon_pos = str.find(":");
|
size_t colon_pos = str.find(':');
|
||||||
if(colon_pos != std::string::npos)
|
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(str[a] >= 32 && str[a] <= 126)
|
||||||
if(data_begin != std::string::npos)
|
data_len++;
|
||||||
{
|
else
|
||||||
std::string header_name = str.substr(0, colon_pos);
|
break;
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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()
|
void Http::load_mimetypes()
|
||||||
|
|||||||
@ -7,20 +7,6 @@
|
|||||||
|
|
||||||
namespace fr
|
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)
|
bool HttpResponse::parse(const std::string &response_data)
|
||||||
{
|
{
|
||||||
body += response_data;
|
body += response_data;
|
||||||
@ -69,7 +55,8 @@ namespace fr
|
|||||||
response += "connection: close_socket\r\n";
|
response += "connection: close_socket\r\n";
|
||||||
if(header_data.find("content-type") == header_data.end())
|
if(header_data.find("content-type") == header_data.end())
|
||||||
response += "content-type: text/html\r\n";
|
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
|
//Add in space
|
||||||
response += "\r\n";
|
response += "\r\n";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user