Mercurial > hg > orthanc
changeset 2045:21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 24 Jun 2016 11:42:23 +0200 |
parents | 0f35383dd6cc |
children | b534834a300e |
files | Core/HttpClient.cpp Core/HttpClient.h Plugins/Engine/OrthancPlugins.cpp |
diffstat | 3 files changed, 36 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/HttpClient.cpp Thu Jun 23 17:32:01 2016 +0200 +++ b/Core/HttpClient.cpp Fri Jun 24 11:42:23 2016 +0200 @@ -233,9 +233,17 @@ } + struct CurlHeaderParameters + { + bool lowerCase_; + HttpClient::HttpHeaders* headers_; + }; + + static size_t CurlHeaderCallback(void *buffer, size_t size, size_t nmemb, void *payload) { - HttpClient::HttpHeaders& headers = *(static_cast<HttpClient::HttpHeaders*>(payload)); + CurlHeaderParameters& parameters = *(static_cast<CurlHeaderParameters*>(payload)); + assert(parameters.headers_ != NULL); size_t length = size * nmemb; if (length == 0) @@ -250,14 +258,19 @@ if (colon != std::string::npos && eol != std::string::npos) { - std::string tmp; - Toolbox::ToLowerCase(tmp, s.substr(0, colon)); + std::string tmp(s.substr(0, colon)); + + if (parameters.lowerCase_) + { + Toolbox::ToLowerCase(tmp); + } + std::string key = Toolbox::StripSpaces(tmp); if (!key.empty()) { std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol)); - headers[key] = value; + (*parameters.headers_) [key] = value; } } @@ -304,7 +317,8 @@ HttpClient::HttpClient() : pimpl_(new PImpl), verifyPeers_(true), - pkcs11Enabled_(false) + pkcs11Enabled_(false), + headersToLowerCase_(true) { Setup(); } @@ -393,6 +407,8 @@ answerBody.clear(); CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); + CurlHeaderParameters headerParameters; + if (answerHeaders == NULL) { CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, NULL)); @@ -400,8 +416,10 @@ } else { + headerParameters.lowerCase_ = headersToLowerCase_; + headerParameters.headers_ = answerHeaders; CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlHeaderCallback)); - CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, answerHeaders)); + CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, &headerParameters)); } #if ORTHANC_SSL_ENABLED == 1
--- a/Core/HttpClient.h Thu Jun 23 17:32:01 2016 +0200 +++ b/Core/HttpClient.h Fri Jun 24 11:42:23 2016 +0200 @@ -66,6 +66,7 @@ std::string clientCertificateKeyFile_; std::string clientCertificateKeyPassword_; bool pkcs11Enabled_; + bool headersToLowerCase_; void Setup(); @@ -232,6 +233,16 @@ return clientCertificateKeyPassword_; } + void SetConvertHeadersToLowerCase(bool lowerCase) + { + headersToLowerCase_ = lowerCase; + } + + bool IsConvertHeadersToLowerCase() const + { + return headersToLowerCase_; + } + static void GlobalInitialize(); static void GlobalFinalize();