Browse Source

updated HttpRequestTask addHeaders

taymindis 9 years ago
parent
commit
590c0e55dc

+ 8 - 2
oxygine/src/HttpRequestTask.cpp

@@ -27,6 +27,9 @@ namespace oxygine
     HttpRequestTask::~HttpRequestTask()
     HttpRequestTask::~HttpRequestTask()
     {
     {
         log::messageln("~HttpRequestTask");
         log::messageln("~HttpRequestTask");
+        if(!_headers.empty()) {
+            _headers.clear();
+        }
     }
     }
 
 
     void HttpRequestTask::setCustomRequests(createHttpRequestCallback cb)
     void HttpRequestTask::setCustomRequests(createHttpRequestCallback cb)
@@ -60,8 +63,11 @@ namespace oxygine
 
 
     void HttpRequestTask::addHeader(const std::string& key, const std::string& value)
     void HttpRequestTask::addHeader(const std::string& key, const std::string& value)
     {
     {
-        OX_ASSERT(!"not implemented");
-        _addHeader(key, value);
+        OX_ASSERT(!"Implmenting");
+        if(!key.empty()) {            
+            _headers.push_back(std::make_pair(key,value));          
+            _addHeader(key, value);            
+        }
     }
     }
 
 
     const std::vector<unsigned char>&   HttpRequestTask::getPostData() const
     const std::vector<unsigned char>&   HttpRequestTask::getPostData() const

+ 2 - 0
oxygine/src/HttpRequestTask.h

@@ -16,6 +16,7 @@ namespace oxygine
         static void init();
         static void init();
         static void release();
         static void release();
 
 
+        typedef std::vector<std::pair<std::string,std::string>>  headers_pair;
         /**dispatching AsyncTask events*/
         /**dispatching AsyncTask events*/
         enum
         enum
         {
         {
@@ -75,5 +76,6 @@ namespace oxygine
         bool _cacheEnabled;
         bool _cacheEnabled;
         std::vector<unsigned char> _response;
         std::vector<unsigned char> _response;
         std::vector<unsigned char> _postData;
         std::vector<unsigned char> _postData;
+        headers_pair _headers;
     };
     };
 }
 }

+ 15 - 7
oxygine/src/core/curl/HttpRequestCurlTask.cpp

@@ -197,7 +197,7 @@ namespace oxygine
         return size;
         return size;
     }
     }
 
 
-    HttpRequestTaskCURL::HttpRequestTaskCURL() : _easy(0), _handle(0)
+    HttpRequestTaskCURL::HttpRequestTaskCURL() : _easy(0), _handle(0), _httpHeaders(NULL)
     {
     {
         _easy = curl_easy_init();
         _easy = curl_easy_init();
     }
     }
@@ -213,6 +213,10 @@ namespace oxygine
         _easy = 0;
         _easy = 0;
     }
     }
 
 
+    void _addHeader(const std::string& key, const std::string& value) {        
+       _httpHeaders = curl_slist_append(_httpHeaders, key + ": " + value);
+    }
+
     void HttpRequestTaskCURL::_run()
     void HttpRequestTaskCURL::_run()
     {
     {
         curl_easy_setopt(_easy, CURLOPT_URL, _url.c_str());
         curl_easy_setopt(_easy, CURLOPT_URL, _url.c_str());
@@ -226,13 +230,17 @@ namespace oxygine
 
 
         //curl_slist *header = curl_slist_append(0, "hello");
         //curl_slist *header = curl_slist_append(0, "hello");
         //curl_easy_setopt(_easy, CURLOPT_HEADER, header);
         //curl_easy_setopt(_easy, CURLOPT_HEADER, header);
+        if(!_httpHeaders) {
+            httpHeaders = curl_slist_append(_httpHeaders, "Content-Type: text/plain");
+        } 
 
 
-        if (!_postData.empty())
-        {
-            curl_slist* headers = NULL; // init to NULL is important
-            //headers = curl_slist_append(headers, "Accept:")
-            headers = curl_slist_append(headers, "Content-Type: text/plain");
-            curl_easy_setopt(_easy, CURLOPT_HTTPHEADER, headers);
+        curl_easy_setopt(_easy, CURLOPT_HTTPHEADER, _httpHeaders);        
+
+        if (!_postData.empty()){
+            // curl_slist* headers = NULL; // init to NULL is important
+            //headers = curl_slist_append(headers, "Accept:")            
+
+            
 
 
             //curl_easy_setopt(_easy, CURLOPT_PORT, 4002);
             //curl_easy_setopt(_easy, CURLOPT_PORT, 4002);
 
 

+ 1 - 0
oxygine/src/core/curl/HttpRequestCurlTask.h

@@ -35,5 +35,6 @@ namespace oxygine
 
 
         file::handle _handle;
         file::handle _handle;
         void* _easy;
         void* _easy;
+        curl_slist* _httpHeaders;
     };
     };
 }
 }