HeadersType GetHeaders(){ HeadersType ret; for(auto h: request_.headers()){ ret.push_back(h); } return ret; }
http::client::response _GetResponse(HttpRequestMethod requestMethod, http::client::request& request, const string& requestBody = "") { auto getResponse = [&]() { switch (requestMethod) { case HttpRequestMethod::Get: return _client->get(request); case HttpRequestMethod::Post: return _client->post(request, requestBody); case HttpRequestMethod::Delete: return _client->delete_(request); } throw runtime_error("HTTP request not implemented"); }; http::client::response response = getResponse(); if (status(response) == http_response::forbidden && (!_accessToken.empty())) { _accessToken = _GetAccessToken(_refreshToken); string headerKey = "Authorization"; request.remove_header(headerKey); request << header(headerKey, _GetAuthorizationHeader()); response = getResponse(); } return response; }
void SetUriString(cr_string s){ request_.uri(s.to_string()); }
void SetBody(cr_string body){ request_.body(body.to_string()); }
std::string GetBody(){ return request_.body(); }
void RemoveHeader(cr_string n){ request_.remove_header(n.to_string()); }
void AddHeader(cr_string n,cr_string v){ request_.add_header(std::make_pair(n.to_string(),v.to_string())); }
use_unknown<IUri> GetUri(){ auto u = ImplementUri::create(request_.uri()); return u.QueryInterface<IUri>(); }
void SetUri(use_unknown<IUri> u){ boost::network::uri::uri uri(u.ToString()); request_.uri(uri); }