mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
* HTTP.{cpp,h} * add 'body' member ot HTTPRes * change HTTPRes::to_string() to add 'Date', 'Content-Length' headers and body
This commit is contained in:
parent
70e9d85a75
commit
2ce61402bb
2 changed files with 25 additions and 1 deletions
12
HTTP.cpp
12
HTTP.cpp
|
@ -334,12 +334,24 @@ namespace http {
|
|||
}
|
||||
|
||||
std::string HTTPRes::to_string() {
|
||||
if (version == "HTTP/1.1" && headers.count("Date") == 0) {
|
||||
std::string date;
|
||||
gen_rfc1123_date(date);
|
||||
add_header("Date", date.c_str());
|
||||
}
|
||||
if (status == "OK" && code != 200)
|
||||
status = HTTPCodeToStatus(code); // update
|
||||
if (body.length() > 0 && headers.count("Content-Length") == 0)
|
||||
add_header("Content-Length", std::to_string(body.length()).c_str());
|
||||
/* build response */
|
||||
std::stringstream ss;
|
||||
ss << version << " " << code << " " << status << CRLF;
|
||||
for (auto & h : headers) {
|
||||
ss << h.first << ": " << h.second << CRLF;
|
||||
}
|
||||
ss << CRLF;
|
||||
if (body.length() > 0)
|
||||
ss << body;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue