Merge topic 'file-curl-httpheader'
8f6cb366
file(DOWNLOAD|UPLOAD): Add HTTPHEADER suboption
This commit is contained in:
commit
4356bd7fe3
|
@ -225,6 +225,9 @@ Options to both ``DOWNLOAD`` and ``UPLOAD`` are:
|
||||||
``USERPWD <username>:<password>``
|
``USERPWD <username>:<password>``
|
||||||
Set username and password for operation.
|
Set username and password for operation.
|
||||||
|
|
||||||
|
``HTTPHEADER <HTTP-header>``
|
||||||
|
HTTP header for operation. Suboption can be repeated several times.
|
||||||
|
|
||||||
Additional options to ``DOWNLOAD`` are:
|
Additional options to ``DOWNLOAD`` are:
|
||||||
|
|
||||||
``EXPECTED_HASH ALGO=<value>``
|
``EXPECTED_HASH ALGO=<value>``
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
file-curl-httpheader
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
* The :command:`file(DOWNLOAD)` and :command:`file(UPLOAD)` commands
|
||||||
|
gained a ``HTTPHEADER <HTTP-header>`` option.
|
|
@ -2483,6 +2483,8 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
|
||||||
bool showProgress = false;
|
bool showProgress = false;
|
||||||
std::string userpwd;
|
std::string userpwd;
|
||||||
|
|
||||||
|
std::list<std::string> curl_headers;
|
||||||
|
|
||||||
while (i != args.end()) {
|
while (i != args.end()) {
|
||||||
if (*i == "TIMEOUT") {
|
if (*i == "TIMEOUT") {
|
||||||
++i;
|
++i;
|
||||||
|
@ -2572,6 +2574,13 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
userpwd = *i;
|
userpwd = *i;
|
||||||
|
} else if (*i == "HTTPHEADER") {
|
||||||
|
++i;
|
||||||
|
if (i == args.end()) {
|
||||||
|
this->SetError("DOWNLOAD missing string for HTTPHEADER.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
curl_headers.push_back(*i);
|
||||||
} else {
|
} else {
|
||||||
// Do not return error for compatibility reason.
|
// Do not return error for compatibility reason.
|
||||||
std::string err = "Unexpected argument: ";
|
std::string err = "Unexpected argument: ";
|
||||||
|
@ -2716,8 +2725,17 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
|
||||||
check_curl_result(res, "DOWNLOAD cannot set user password: ");
|
check_curl_result(res, "DOWNLOAD cannot set user password: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct curl_slist* headers = CM_NULLPTR;
|
||||||
|
for (std::list<std::string>::const_iterator h = curl_headers.begin();
|
||||||
|
h != curl_headers.end(); ++h) {
|
||||||
|
headers = ::curl_slist_append(headers, h->c_str());
|
||||||
|
}
|
||||||
|
::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
|
||||||
res = ::curl_easy_perform(curl);
|
res = ::curl_easy_perform(curl);
|
||||||
|
|
||||||
|
::curl_slist_free_all(headers);
|
||||||
|
|
||||||
/* always cleanup */
|
/* always cleanup */
|
||||||
g_curl.release();
|
g_curl.release();
|
||||||
::curl_easy_cleanup(curl);
|
::curl_easy_cleanup(curl);
|
||||||
|
@ -2798,6 +2816,8 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
|
||||||
bool showProgress = false;
|
bool showProgress = false;
|
||||||
std::string userpwd;
|
std::string userpwd;
|
||||||
|
|
||||||
|
std::list<std::string> curl_headers;
|
||||||
|
|
||||||
while (i != args.end()) {
|
while (i != args.end()) {
|
||||||
if (*i == "TIMEOUT") {
|
if (*i == "TIMEOUT") {
|
||||||
++i;
|
++i;
|
||||||
|
@ -2838,6 +2858,13 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
userpwd = *i;
|
userpwd = *i;
|
||||||
|
} else if (*i == "HTTPHEADER") {
|
||||||
|
++i;
|
||||||
|
if (i == args.end()) {
|
||||||
|
this->SetError("UPLOAD missing string for HTTPHEADER.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
curl_headers.push_back(*i);
|
||||||
} else {
|
} else {
|
||||||
// Do not return error for compatibility reason.
|
// Do not return error for compatibility reason.
|
||||||
std::string err = "Unexpected argument: ";
|
std::string err = "Unexpected argument: ";
|
||||||
|
@ -2956,8 +2983,17 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
|
||||||
check_curl_result(res, "UPLOAD cannot set user password: ");
|
check_curl_result(res, "UPLOAD cannot set user password: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct curl_slist* headers = CM_NULLPTR;
|
||||||
|
for (std::list<std::string>::const_iterator h = curl_headers.begin();
|
||||||
|
h != curl_headers.end(); ++h) {
|
||||||
|
headers = ::curl_slist_append(headers, h->c_str());
|
||||||
|
}
|
||||||
|
::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
|
||||||
res = ::curl_easy_perform(curl);
|
res = ::curl_easy_perform(curl);
|
||||||
|
|
||||||
|
::curl_slist_free_all(headers);
|
||||||
|
|
||||||
/* always cleanup */
|
/* always cleanup */
|
||||||
g_curl.release();
|
g_curl.release();
|
||||||
::curl_easy_cleanup(curl);
|
::curl_easy_cleanup(curl);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
|
@ -0,0 +1,4 @@
|
||||||
|
^CMake Error at DOWNLOAD-httpheader-not-set.cmake:[0-9]+ \(file\):
|
||||||
|
file DOWNLOAD missing string for HTTPHEADER.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:[0-9]+ \(include\)$
|
|
@ -0,0 +1 @@
|
||||||
|
file(DOWNLOAD "" "" HTTPHEADER "Content-Type: application/x-compressed-tar" HTTPHEADER)
|
|
@ -2,8 +2,10 @@ include(RunCMake)
|
||||||
|
|
||||||
run_cmake(DOWNLOAD-hash-mismatch)
|
run_cmake(DOWNLOAD-hash-mismatch)
|
||||||
run_cmake(DOWNLOAD-unused-argument)
|
run_cmake(DOWNLOAD-unused-argument)
|
||||||
|
run_cmake(DOWNLOAD-httpheader-not-set)
|
||||||
run_cmake(DOWNLOAD-pass-not-set)
|
run_cmake(DOWNLOAD-pass-not-set)
|
||||||
run_cmake(UPLOAD-unused-argument)
|
run_cmake(UPLOAD-unused-argument)
|
||||||
|
run_cmake(UPLOAD-httpheader-not-set)
|
||||||
run_cmake(UPLOAD-pass-not-set)
|
run_cmake(UPLOAD-pass-not-set)
|
||||||
run_cmake(INSTALL-DIRECTORY)
|
run_cmake(INSTALL-DIRECTORY)
|
||||||
run_cmake(INSTALL-MESSAGE-bad)
|
run_cmake(INSTALL-MESSAGE-bad)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
|
@ -0,0 +1,4 @@
|
||||||
|
^CMake Error at UPLOAD-httpheader-not-set.cmake:[0-9]+ \(file\):
|
||||||
|
file UPLOAD missing string for HTTPHEADER.
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:[0-9]+ \(include\)$
|
|
@ -0,0 +1 @@
|
||||||
|
file(UPLOAD "" "" HTTPHEADER "Content-Type: application/x-compressed-tar" HTTPHEADER)
|
Loading…
Reference in New Issue