Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
2040:6ea2e264ca50 | 2041:9f61ca1e3eb3 |
---|---|
386 pimpl_->userHeaders_ = NULL; | 386 pimpl_->userHeaders_ = NULL; |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 | 390 |
391 bool HttpClient::ApplyInternal(std::string& answer, | 391 bool HttpClient::ApplyInternal(std::string& answerBody, |
392 HttpHeaders* headers) | 392 HttpHeaders* answerHeaders) |
393 { | 393 { |
394 answer.clear(); | 394 answerBody.clear(); |
395 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); | 395 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); |
396 | 396 |
397 if (headers == NULL) | 397 if (answerHeaders == NULL) |
398 { | 398 { |
399 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, NULL)); | 399 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, NULL)); |
400 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, NULL)); | 400 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, NULL)); |
401 } | 401 } |
402 else | 402 else |
403 { | 403 { |
404 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlHeaderCallback)); | 404 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlHeaderCallback)); |
405 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, headers)); | 405 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, answerHeaders)); |
406 } | 406 } |
407 | 407 |
408 #if ORTHANC_SSL_ENABLED == 1 | 408 #if ORTHANC_SSL_ENABLED == 1 |
409 // Setup HTTPS-related options | 409 // Setup HTTPS-related options |
410 | 410 |
591 | 591 |
592 bool success = (status >= 200 && status < 300); | 592 bool success = (status >= 200 && status < 300); |
593 | 593 |
594 if (success) | 594 if (success) |
595 { | 595 { |
596 buffer.Flatten(answer); | 596 buffer.Flatten(answerBody); |
597 } | 597 } |
598 else | 598 else |
599 { | 599 { |
600 answer.clear(); | 600 answerBody.clear(); |
601 LOG(INFO) << "Error in HTTP request, received HTTP status " << status | 601 LOG(INFO) << "Error in HTTP request, received HTTP status " << status |
602 << " (" << EnumerationToString(lastStatus_) << ")"; | 602 << " (" << EnumerationToString(lastStatus_) << ")"; |
603 } | 603 } |
604 | 604 |
605 return success; | 605 return success; |
606 } | 606 } |
607 | 607 |
608 | 608 |
609 bool HttpClient::ApplyInternal(Json::Value& answer, | 609 bool HttpClient::ApplyInternal(Json::Value& answerBody, |
610 HttpClient::HttpHeaders* answerHeaders) | 610 HttpClient::HttpHeaders* answerHeaders) |
611 { | 611 { |
612 std::string s; | 612 std::string s; |
613 if (ApplyInternal(s, answerHeaders)) | 613 if (ApplyInternal(s, answerHeaders)) |
614 { | 614 { |
615 Json::Reader reader; | 615 Json::Reader reader; |
616 return reader.parse(s, answer); | 616 return reader.parse(s, answerBody); |
617 } | 617 } |
618 else | 618 else |
619 { | 619 { |
620 return false; | 620 return false; |
621 } | 621 } |
687 { | 687 { |
688 GlobalParameters::GetInstance().SetDefaultTimeout(timeout); | 688 GlobalParameters::GetInstance().SetDefaultTimeout(timeout); |
689 } | 689 } |
690 | 690 |
691 | 691 |
692 void HttpClient::ApplyAndThrowException(std::string& answer) | 692 void HttpClient::ApplyAndThrowException(std::string& answerBody) |
693 { | 693 { |
694 if (!Apply(answer)) | 694 if (!Apply(answerBody)) |
695 { | 695 { |
696 ThrowException(GetLastStatus()); | 696 ThrowException(GetLastStatus()); |
697 } | 697 } |
698 } | 698 } |
699 | |
699 | 700 |
700 void HttpClient::ApplyAndThrowException(Json::Value& answer) | 701 void HttpClient::ApplyAndThrowException(Json::Value& answerBody) |
701 { | 702 { |
702 if (!Apply(answer)) | 703 if (!Apply(answerBody)) |
704 { | |
705 ThrowException(GetLastStatus()); | |
706 } | |
707 } | |
708 | |
709 | |
710 void HttpClient::ApplyAndThrowException(std::string& answerBody, | |
711 HttpHeaders& answerHeaders) | |
712 { | |
713 if (!Apply(answerBody, answerHeaders)) | |
714 { | |
715 ThrowException(GetLastStatus()); | |
716 } | |
717 } | |
718 | |
719 | |
720 void HttpClient::ApplyAndThrowException(Json::Value& answerBody, | |
721 HttpHeaders& answerHeaders) | |
722 { | |
723 if (!Apply(answerBody, answerHeaders)) | |
703 { | 724 { |
704 ThrowException(GetLastStatus()); | 725 ThrowException(GetLastStatus()); |
705 } | 726 } |
706 } | 727 } |
707 | 728 |