HTTP construction and parsing bug fixes
Don't trim received HTTP body if content length isn't specified. Don't add duplicate \r\n after POST string data, if no POST data is specified.
This commit is contained in:
parent
a77d7e287a
commit
41f600cd11
@ -137,7 +137,10 @@ namespace fr
|
|||||||
if(++iter != get_data.end())
|
if(++iter != get_data.end())
|
||||||
post_string += "&";
|
post_string += "&";
|
||||||
}
|
}
|
||||||
|
if(!post_string.empty())
|
||||||
|
{
|
||||||
post_string += "\r\n";
|
post_string += "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
//Add in required headers if they're missing
|
//Add in required headers if they're missing
|
||||||
if(header_data.find("Connection") == header_data.end())
|
if(header_data.find("Connection") == header_data.end())
|
||||||
|
|||||||
@ -51,7 +51,7 @@ namespace fr
|
|||||||
return fr::Socket::Status::HttpBodyTooBig;
|
return fr::Socket::Status::HttpBodyTooBig;
|
||||||
|
|
||||||
//Cut off any data if it exceeds content length, todo: potentially an issue, could cut the next request off
|
//Cut off any data if it exceeds content length, todo: potentially an issue, could cut the next request off
|
||||||
if(body.size() > content_length)
|
if(content_length > 0 && body.size() > content_length)
|
||||||
body.resize(content_length);
|
body.resize(content_length);
|
||||||
else if(body.size() < content_length)
|
else if(body.size() < content_length)
|
||||||
return fr::Socket::Status::NotEnoughData;
|
return fr::Socket::Status::NotEnoughData;
|
||||||
@ -78,7 +78,7 @@ namespace fr
|
|||||||
response += "connection: keep-alive\r\n";
|
response += "connection: keep-alive\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";
|
||||||
if(header_data.find("content-length") == header_data.end())
|
if(header_data.find("content-length") == header_data.end() && !body.empty())
|
||||||
response += "content-length: " + std::to_string(body.size()) + "\r\n";
|
response += "content-length: " + std::to_string(body.size()) + "\r\n";
|
||||||
|
|
||||||
//Add in space
|
//Add in space
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user