diff options
author | Brad King <brad.king@kitware.com> | 2017-05-05 13:50:52 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-05-05 13:50:58 (GMT) |
commit | e1ae739e1f4b868dffcb4a08cfacde3680dca3aa (patch) | |
tree | b4303ba008277f4924b6c93253f11155dffc6c2b /Source/CTest/cmCTestCurl.cxx | |
parent | b605bdfd03ccb0c7003a110004afe7981853bc76 (diff) | |
parent | 1a7d00bd12f261428edb8fef09461bee8067ceee (diff) | |
download | CMake-e1ae739e1f4b868dffcb4a08cfacde3680dca3aa.zip CMake-e1ae739e1f4b868dffcb4a08cfacde3680dca3aa.tar.gz CMake-e1ae739e1f4b868dffcb4a08cfacde3680dca3aa.tar.bz2 |
Merge topic 'ctest_submit_headers'
1a7d00bd ctest_submit: Add HTTPHEADER option
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !793
Diffstat (limited to 'Source/CTest/cmCTestCurl.cxx')
-rw-r--r-- | Source/CTest/cmCTestCurl.cxx | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Source/CTest/cmCTestCurl.cxx b/Source/CTest/cmCTestCurl.cxx index 06b5e81..b80ea5a 100644 --- a/Source/CTest/cmCTestCurl.cxx +++ b/Source/CTest/cmCTestCurl.cxx @@ -143,9 +143,17 @@ bool cmCTestCurl::UploadFile(std::string const& local_file, ::curl_easy_setopt(this->Curl, CURLOPT_WRITEFUNCTION, curlWriteMemoryCallback); ::curl_easy_setopt(this->Curl, CURLOPT_DEBUGFUNCTION, curlDebugCallback); - // Be sure to set Content-Type to satisfy fussy modsecurity rules + // Set Content-Type to satisfy fussy modsecurity rules. struct curl_slist* headers = ::curl_slist_append(CM_NULLPTR, "Content-Type: text/xml"); + // Add any additional headers that the user specified. + for (std::vector<std::string>::const_iterator h = this->HttpHeaders.begin(); + h != this->HttpHeaders.end(); ++h) { + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, + " Add HTTP Header: \"" << *h << "\"" << std::endl, + this->Quiet); + headers = ::curl_slist_append(headers, h->c_str()); + } ::curl_easy_setopt(this->Curl, CURLOPT_HTTPHEADER, headers); std::vector<char> responseData; std::vector<char> debugData; @@ -203,7 +211,22 @@ bool cmCTestCurl::HttpRequest(std::string const& url, ::curl_easy_setopt(this->Curl, CURLOPT_DEBUGDATA, (void*)&debugData); ::curl_easy_setopt(this->Curl, CURLOPT_FAILONERROR, 1); + // Add headers if any were specified. + struct curl_slist* headers = CM_NULLPTR; + if (!this->HttpHeaders.empty()) { + for (std::vector<std::string>::const_iterator h = + this->HttpHeaders.begin(); + h != this->HttpHeaders.end(); ++h) { + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, + " Add HTTP Header: \"" << *h << "\"" << std::endl, + this->Quiet); + headers = ::curl_slist_append(headers, h->c_str()); + } + } + + ::curl_easy_setopt(this->Curl, CURLOPT_HTTPHEADER, headers); CURLcode res = ::curl_easy_perform(this->Curl); + ::curl_slist_free_all(headers); if (!responseData.empty()) { response = std::string(responseData.begin(), responseData.end()); |