Browse Source

UI: Add alternate constructor for RemoteTextThread

Allows specifying extra headers.
jp9000 7 years ago
parent
commit
08e6dcd516
2 changed files with 18 additions and 0 deletions
  1. 3 0
      UI/remote-text.cpp
  2. 15 0
      UI/remote-text.hpp

+ 3 - 0
UI/remote-text.cpp

@@ -61,6 +61,9 @@ void RemoteTextThread::run()
 					contentTypeString.c_str());
 		}
 
+		for (std::string &h : extraHeaders)
+			header = curl_slist_append(header, h.c_str());
+
 		curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str());
 		curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER,
 				header);

+ 15 - 0
UI/remote-text.hpp

@@ -28,6 +28,8 @@ class RemoteTextThread : public QThread {
 	std::string contentType;
 	std::string postData;
 
+	std::vector<std::string> extraHeaders;
+
 	int timeoutSec = 0;
 
 	void run() override;
@@ -46,6 +48,19 @@ public:
 		  postData    (postData_),
 		  timeoutSec  (timeoutSec_)
 	{}
+
+	inline RemoteTextThread(
+			std::string url_,
+			std::vector<std::string> &&extraHeaders_,
+			std::string contentType_ = std::string(),
+			std::string postData_ = std::string(),
+			int timeoutSec_ = 0)
+		: url          (url_),
+		  contentType  (contentType_),
+		  postData     (postData_),
+		  extraHeaders (std::move(extraHeaders_)),
+		  timeoutSec   (timeoutSec_)
+	{}
 };
 
 bool GetRemoteFile(