diff options
author | Zack Galbreath <zack.galbreath@kitware.com> | 2017-05-03 14:50:04 (GMT) |
---|---|---|
committer | Zack Galbreath <zack.galbreath@kitware.com> | 2017-05-04 16:21:21 (GMT) |
commit | 1a7d00bd12f261428edb8fef09461bee8067ceee (patch) | |
tree | 7d998892f75ff11470ff6c884d4e168bdddd6c63 /Source/CTest/cmCTestCurl.cxx | |
parent | 294cf948dc37799e1980685afbf1fa585ad5b0fb (diff) | |
download | CMake-1a7d00bd12f261428edb8fef09461bee8067ceee.zip CMake-1a7d00bd12f261428edb8fef09461bee8067ceee.tar.gz CMake-1a7d00bd12f261428edb8fef09461bee8067ceee.tar.bz2 |
ctest_submit: Add HTTPHEADER option
Allow CTest script writers to specify additional HTTP headers to be sent
to CDash during submission.
The motivating case for this feature is a corresponding change in CDash.
This will allow projects to refuse submissions from any site not bearing
a valid authentication token.
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()); |