MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / HTTPReply

Function HTTPReply

src/rpc/core/rpcprotocol.cpp:59–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57static string rfc1123Time() { return DateTimeStrFormat("%a, %d %b %Y %H:%M:%S +0000", GetTime()); }
58
59string HTTPReply(int nStatus, const string& strMsg, bool keepalive) {
60 if (nStatus == HTTP_UNAUTHORIZED)
61 return strprintf(
62 "HTTP/1.0 401 Authorization Required\r\n"
63 "Date: %s\r\n"
64 "Server: Coin-json-rpc/%s\r\n"
65 "WWW-Authenticate: Basic realm=\"jsonrpc\"\r\n"
66 "Content-Type: text/html\r\n"
67 "Content-Length: 296\r\n"
68 "\r\n"
69 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\r\n"
70 "\"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">\r\n"
71 "<HTML>\r\n"
72 "<HEAD>\r\n"
73 "<TITLE>Error</TITLE>\r\n"
74 "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>\r\n"
75 "</HEAD>\r\n"
76 "<BODY><H1>401 Unauthorized.</H1></BODY>\r\n"
77 "</HTML>\r\n",
78 rfc1123Time(), FormatFullVersion());
79 const char* cStatus;
80 if (nStatus == HTTP_OK)
81 cStatus = "OK";
82 else if (nStatus == HTTP_BAD_REQUEST)
83 cStatus = "Bad Request";
84 else if (nStatus == HTTP_FORBIDDEN)
85 cStatus = "Forbidden";
86 else if (nStatus == HTTP_NOT_FOUND)
87 cStatus = "Not Found";
88 else if (nStatus == HTTP_INTERNAL_SERVER_ERROR)
89 cStatus = "Internal Server Error";
90 else
91 cStatus = "";
92 return strprintf(
93 "HTTP/1.1 %d %s\r\n"
94 "Date: %s\r\n"
95 "Connection: %s\r\n"
96 "Content-Length: %u\r\n"
97 "Content-Type: application/json\r\n"
98 "Access-Control-Allow-Origin: *\r\n"
99 "Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE, PATCH\r\n"
100 "Access-Control-Max-Age: 3600\r\n"
101 "Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept\r\n"
102 "Server: Coin-json-rpc/%s\r\n"
103 "\r\n"
104 "%s",
105 nStatus, cStatus, rfc1123Time(), keepalive ? "keep-alive" : "close", strMsg.size(), FormatFullVersion(),
106 strMsg);
107}
108
109bool ReadHTTPRequestLine(basic_istream<char>& stream, int& proto, string& http_method, string& http_uri) {
110 string str;

Callers

nothing calls this directly

Calls 3

rfc1123TimeFunction · 0.85
FormatFullVersionFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected