Enhanced CTest HTTP Request API to support PUT file uploads.
This commit is contained in:
parent
646e71f290
commit
0a0788a72d
|
@ -172,22 +172,42 @@ HTTPResponseCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
|||
//----------------------------------------------------------------------------
|
||||
int cmCTest::HTTPRequest(std::string url, HTTPMethod method,
|
||||
std::string& response,
|
||||
std::string fields, int timeout)
|
||||
std::string fields,
|
||||
std::string putFile, int timeout)
|
||||
{
|
||||
CURL* curl;
|
||||
FILE* file;
|
||||
::curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = ::curl_easy_init();
|
||||
|
||||
//set request options
|
||||
if(method == cmCTest::HTTP_GET && fields.size())
|
||||
//set request options based on method
|
||||
switch(method)
|
||||
{
|
||||
url += "?" + fields;
|
||||
}
|
||||
else
|
||||
{
|
||||
::curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||
::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str());
|
||||
case cmCTest::HTTP_POST:
|
||||
::curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||
::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str());
|
||||
break;
|
||||
case cmCTest::HTTP_PUT:
|
||||
if(!cmSystemTools::FileExists(putFile.c_str()))
|
||||
{
|
||||
response = "Error: File ";
|
||||
response += putFile + " does not exist.\n";
|
||||
return -1;
|
||||
}
|
||||
::curl_easy_setopt(curl, CURLOPT_PUT, 1);
|
||||
file = ::fopen(putFile.c_str(), "rb");
|
||||
::curl_easy_setopt(curl, CURLOPT_INFILE, file);
|
||||
//fall through to append GET fields
|
||||
case cmCTest::HTTP_GET:
|
||||
if(fields.size())
|
||||
{
|
||||
url += "?" + fields;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
|
||||
::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||
|
|
|
@ -83,7 +83,8 @@ public:
|
|||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
enum HTTPMethod {
|
||||
HTTP_GET,
|
||||
HTTP_POST
|
||||
HTTP_POST,
|
||||
HTTP_PUT
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -91,7 +92,8 @@ public:
|
|||
*/
|
||||
static int HTTPRequest(std::string url, HTTPMethod method,
|
||||
std::string& response,
|
||||
std::string fields = "", int timeout = 10);
|
||||
std::string fields = "",
|
||||
std::string putFile = "", int timeout = 0);
|
||||
#endif
|
||||
|
||||
/** Get a testing part id from its string name. Returns PartCount
|
||||
|
|
Loading…
Reference in New Issue