VarValue Call(RCString method, const vector<VarValue>& params = vector<VarValue>()) { Ext::WebClient wc = GetWebClient(); wc.Proxy = nullptr; //!!!? wc.CacheLevel = RequestCacheLevel::BypassCache; wc.Credentials.UserName = !Login.empty() ? Login : RpcUrl.UserName; wc.Credentials.Password = !Password.empty() ? Password : RpcUrl.Password; String sjson; try { DBG_LOCAL_IGNORE_CONDITION_OBJ(error_condition(500, http_category())); sjson = wc.UploadString(RpcUrl.ToString(), JsonRpc.Request(method, params)); } catch (WebException& ex) { if (ex.code() == http_error::unauthorized) throw; sjson = ex.Result; } #ifdef X_DEBUG//!!!D cout << sjson << endl; #endif EXT_LOCKED(MtxHeaders, Headers = wc.get_ResponseHeaders()); /*!!!R XStratum = h.Get("X-Stratum"); XSwitchTo = h.Get("X-Switch-To"); XHostList = h.Get("X-Host-List");*/ return JsonRpc.ProcessResponse(ParseJson(sjson)); }
/** populates a default-response content, possibly modifying a few response headers, too. * * \return the newly created response content or a null ptr if the statuc code forbids content. * * \note Modified headers are "Content-Type" and "Content-Length". */ void HttpRequest::writeDefaultResponseContent() { if (isResponseContentForbidden()) return; std::string codeStr = http_category().message(static_cast<int>(status)); char buf[1024]; int nwritten = snprintf(buf, sizeof(buf), "<html>" "<head><title>%s</title></head>" "<body><h1>%d %s</h1></body>" "</html>\r\n", codeStr.c_str(), status, codeStr.c_str() ); responseHeaders.overwrite("Content-Type", "text/html"); char slen[64]; snprintf(slen, sizeof(slen), "%d", nwritten); responseHeaders.overwrite("Content-Length", slen); write<BufferSource>(Buffer::fromCopy(buf, nwritten)); }
std::string HttpRequest::statusStr(HttpStatus value) { return http_category().message(static_cast<int>(value)); }