UI: Add request type param to GetRemoteText

master
Yuriy Chumak 2021-06-27 04:07:44 -07:00 committed by jp9000
parent c4840ddba0
commit 37b9ece904
6 changed files with 25 additions and 10 deletions

View File

@ -212,7 +212,7 @@ try {
auto func = [&]() {
success = GetRemoteFile(url, output, error, nullptr,
"application/x-www-form-urlencoded",
"application/x-www-form-urlencoded", "",
post_data.c_str(),
std::vector<std::string>(), nullptr, 5);
};

View File

@ -58,8 +58,8 @@ try {
auto func = [&]() {
success = GetRemoteFile(RESTREAM_STREAMKEY_URL, output, error,
nullptr, "application/json", nullptr,
headers, nullptr, 5);
nullptr, "application/json", "",
nullptr, headers, nullptr, 5);
};
ExecThreadedWithoutBlocking(

View File

@ -78,8 +78,8 @@ try {
auto func = [&]() {
success = GetRemoteFile("https://api.twitch.tv/kraken/channel",
output, error, &error_code,
"application/json", nullptr, headers,
nullptr, 5);
"application/json", "", nullptr,
headers, nullptr, 5);
};
ExecThreadedWithoutBlocking(

View File

@ -121,7 +121,8 @@ static size_t header_write(char *ptr, size_t size, size_t nmemb,
bool GetRemoteFile(const char *url, std::string &str, std::string &error,
long *responseCode, const char *contentType,
const char *postData, std::vector<std::string> extraHeaders,
std::string request_type, const char *postData,
std::vector<std::string> extraHeaders,
std::string *signature, int timeoutSec)
{
vector<string> header_in_list;
@ -178,7 +179,21 @@ bool GetRemoteFile(const char *url, std::string &str, std::string &error,
// A lot of servers don't yet support ALPN
curl_easy_setopt(curl.get(), CURLOPT_SSL_ENABLE_ALPN, 0);
#endif
if (!request_type.empty()) {
if (request_type != "GET")
curl_easy_setopt(curl.get(),
CURLOPT_CUSTOMREQUEST,
request_type.c_str());
// Special case of "POST"
if (request_type == "POST") {
curl_easy_setopt(curl.get(), CURLOPT_POST, 1);
if (!postData)
curl_easy_setopt(curl.get(),
CURLOPT_POSTFIELDS,
"{}");
}
}
if (postData) {
curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS,
postData);

View File

@ -66,6 +66,6 @@ public:
bool GetRemoteFile(
const char *url, std::string &str, std::string &error,
long *responseCode = nullptr, const char *contentType = nullptr,
const char *postData = nullptr,
std::string request_type = "", const char *postData = nullptr,
std::vector<std::string> extraHeaders = std::vector<std::string>(),
std::string *signature = nullptr, int timeoutSec = 0);

View File

@ -370,7 +370,7 @@ try {
string data;
bool success = GetRemoteFile(url, data, error, &responseCode, nullptr,
nullptr, extraHeaders, &signature);
"", nullptr, extraHeaders, &signature);
if (!success || (responseCode != 200 && responseCode != 304)) {
if (responseCode == 404)
@ -570,7 +570,7 @@ try {
* get manifest from server */
success = GetRemoteFile(WIN_MANIFEST_URL, text, error, &responseCode,
nullptr, nullptr, extraHeaders, &signature);
nullptr, "", nullptr, extraHeaders, &signature);
if (!success || (responseCode != 200 && responseCode != 304)) {
if (responseCode == 404)
@ -766,7 +766,7 @@ try {
* get json from server */
success = GetRemoteFile(WIN_WHATSNEW_URL, text, error, &responseCode,
nullptr, nullptr, extraHeaders, &signature);
nullptr, "", nullptr, extraHeaders, &signature);
if (!success || (responseCode != 200 && responseCode != 304)) {
if (responseCode == 404)