|
|
@ -206,42 +206,33 @@ namespace util |
|
|
|
const char HTTP_HEADER_KV_SEP[] = ": "; |
|
|
|
const char HTTP_HEADER_KV_SEP[] = ": "; |
|
|
|
const char HTTP_CRLF[] = "\r\n"; |
|
|
|
const char HTTP_CRLF[] = "\r\n"; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<boost::asio::const_buffer> HTTPConnection::reply::to_buffers(int status) |
|
|
|
std::string HTTPConnection::reply::to_string(int code) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<boost::asio::const_buffer> buffers; |
|
|
|
std::stringstream ss(""); |
|
|
|
if (headers.size () > 0) |
|
|
|
if (headers.size () > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
status_string = "HTTP/1.1 "; |
|
|
|
const char *status; |
|
|
|
status_string += std::to_string (status); |
|
|
|
switch (code) |
|
|
|
status_string += " "; |
|
|
|
{ |
|
|
|
switch (status) |
|
|
|
case 105: status = "Name Not Resolved"; break; |
|
|
|
{ |
|
|
|
case 200: status = "OK"; break; |
|
|
|
case 105: status_string += "Name Not Resolved"; break; |
|
|
|
case 400: status = "Bad Request"; break; |
|
|
|
case 200: status_string += "OK"; break; |
|
|
|
case 404: status = "Not Found"; break; |
|
|
|
case 400: status_string += "Bad Request"; break; |
|
|
|
case 408: status = "Request Timeout"; break; |
|
|
|
case 404: status_string += "Not Found"; break; |
|
|
|
case 500: status = "Internal Server Error"; break; |
|
|
|
case 408: status_string += "Request Timeout"; break; |
|
|
|
case 502: status = "Bad Gateway"; break; |
|
|
|
case 500: status_string += "Internal Server Error"; break; |
|
|
|
case 503: status = "Not Implemented"; break; |
|
|
|
case 502: status_string += "Bad Gateway"; break; |
|
|
|
case 504: status = "Gateway Timeout"; break; |
|
|
|
case 503: status_string += "Not Implemented"; break; |
|
|
|
default: status = "WTF"; |
|
|
|
case 504: status_string += "Gateway Timeout"; break; |
|
|
|
} |
|
|
|
default: status_string += "WTF"; |
|
|
|
ss << "HTTP/1.1 " << code << "" << status << HTTP_CRLF; |
|
|
|
} |
|
|
|
for (header & h : headers) { |
|
|
|
buffers.push_back(boost::asio::buffer(status_string, status_string.size())); |
|
|
|
ss << h.name << HTTP_HEADER_KV_SEP << h.value << HTTP_CRLF; |
|
|
|
buffers.push_back(boost::asio::buffer(HTTP_CRLF)); |
|
|
|
} |
|
|
|
|
|
|
|
ss << HTTP_CRLF; /* end of headers */ |
|
|
|
for (std::size_t i = 0; i < headers.size(); ++i) |
|
|
|
} |
|
|
|
{ |
|
|
|
ss << content; |
|
|
|
header& h = headers[i]; |
|
|
|
return ss.str(); |
|
|
|
buffers.push_back(boost::asio::buffer(h.name)); |
|
|
|
|
|
|
|
buffers.push_back(boost::asio::buffer(HTTP_HEADER_KV_SEP)); |
|
|
|
|
|
|
|
buffers.push_back(boost::asio::buffer(h.value)); |
|
|
|
|
|
|
|
buffers.push_back(boost::asio::buffer(HTTP_CRLF)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
buffers.push_back(boost::asio::buffer(HTTP_CRLF)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
buffers.push_back(boost::asio::buffer(content)); |
|
|
|
|
|
|
|
return buffers; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HTTPConnection::Terminate () |
|
|
|
void HTTPConnection::Terminate () |
|
|
|