فهرست منبع

UI: Add request type param to GetRemoteText

Yuriy Chumak 4 سال پیش
والد
کامیت
37b9ece904
6فایلهای تغییر یافته به همراه26 افزوده شده و 11 حذف شده
  1. 1 1
      UI/auth-oauth.cpp
  2. 2 2
      UI/auth-restream.cpp
  3. 2 2
      UI/auth-twitch.cpp
  4. 17 2
      UI/remote-text.cpp
  5. 1 1
      UI/remote-text.hpp
  6. 3 3
      UI/win-update/win-update.cpp

+ 1 - 1
UI/auth-oauth.cpp

@@ -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);
 	};

+ 2 - 2
UI/auth-restream.cpp

@@ -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(

+ 2 - 2
UI/auth-twitch.cpp

@@ -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(

+ 17 - 2
UI/remote-text.cpp

@@ -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);

+ 1 - 1
UI/remote-text.hpp

@@ -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);

+ 3 - 3
UI/win-update/win-update.cpp

@@ -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)