Mercurial > hg > orthanc
diff Core/HttpClient.cpp @ 2041:9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 Jun 2016 17:08:09 +0200 |
parents | 6ea2e264ca50 |
children | 0f35383dd6cc |
line wrap: on
line diff
--- a/Core/HttpClient.cpp Tue Jun 21 16:34:30 2016 +0200 +++ b/Core/HttpClient.cpp Tue Jun 21 17:08:09 2016 +0200 @@ -388,13 +388,13 @@ } - bool HttpClient::ApplyInternal(std::string& answer, - HttpHeaders* headers) + bool HttpClient::ApplyInternal(std::string& answerBody, + HttpHeaders* answerHeaders) { - answer.clear(); + answerBody.clear(); CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); - if (headers == NULL) + if (answerHeaders == NULL) { CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, NULL)); CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, NULL)); @@ -402,7 +402,7 @@ else { CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlHeaderCallback)); - CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, headers)); + CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, answerHeaders)); } #if ORTHANC_SSL_ENABLED == 1 @@ -593,11 +593,11 @@ if (success) { - buffer.Flatten(answer); + buffer.Flatten(answerBody); } else { - answer.clear(); + answerBody.clear(); LOG(INFO) << "Error in HTTP request, received HTTP status " << status << " (" << EnumerationToString(lastStatus_) << ")"; } @@ -606,14 +606,14 @@ } - bool HttpClient::ApplyInternal(Json::Value& answer, + bool HttpClient::ApplyInternal(Json::Value& answerBody, HttpClient::HttpHeaders* answerHeaders) { std::string s; if (ApplyInternal(s, answerHeaders)) { Json::Reader reader; - return reader.parse(s, answer); + return reader.parse(s, answerBody); } else { @@ -689,17 +689,38 @@ } - void HttpClient::ApplyAndThrowException(std::string& answer) + void HttpClient::ApplyAndThrowException(std::string& answerBody) + { + if (!Apply(answerBody)) + { + ThrowException(GetLastStatus()); + } + } + + + void HttpClient::ApplyAndThrowException(Json::Value& answerBody) { - if (!Apply(answer)) + if (!Apply(answerBody)) + { + ThrowException(GetLastStatus()); + } + } + + + void HttpClient::ApplyAndThrowException(std::string& answerBody, + HttpHeaders& answerHeaders) + { + if (!Apply(answerBody, answerHeaders)) { ThrowException(GetLastStatus()); } } - void HttpClient::ApplyAndThrowException(Json::Value& answer) + + void HttpClient::ApplyAndThrowException(Json::Value& answerBody, + HttpHeaders& answerHeaders) { - if (!Apply(answer)) + if (!Apply(answerBody, answerHeaders)) { ThrowException(GetLastStatus()); }