this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Revision:
102:9748f290a1a5
Parent:
101:1cfd468e5009
Child:
103:7b566b522427
--- a/source/WiFiManager.cpp	Mon Apr 22 19:36:31 2019 +0000
+++ b/source/WiFiManager.cpp	Wed Apr 24 17:34:17 2019 +0000
@@ -691,7 +691,7 @@
         }
         else {            
             if(http_response_hdr_sent == false && chunkNum==1){ // only do this for first chunk
-                bool status = copyResponseHdr2Queue();  
+                bool status = copyResponseHdr2Queue(buf);  
                 if(status == true){
                     printf("[WIFI-MAN] Http Response header copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen);
                     hdrLen =  at_data_resp->dataLen;
@@ -719,58 +719,40 @@
     at_data_resp = NULL;
 }
 
-bool WiFiManager::copyResponseHdr2Queue()
+bool WiFiManager::copyResponseHdr2Queue(const uint8_t * buf)
 {
-    int numChars = 0;
-    // create message pointer for response header generation
-    char * msgPtr = (char *)at_data_resp->buffer;
-    // do status line
-    int wait_cnt = 0;
-    while(http_response == NULL && wait_cnt<100)
+    const char *arbPtr = (const char *)buf - MAX_HTTP_HDR_LEN;
+    const char *hdrPtr;
+    int len;
+    bool hdrFound = false;
+    int i;
+    for(i=0;i<(MAX_HTTP_HDR_LEN-50);i++)
     {
-        printf("[WIFI-MAN] response pointer NULL waiting for %dms so far!!\r\n", 10*wait_cnt++);
-        wait_ms(10);
-        //return false;
+        // get location of start of the http header string
+        hdrPtr = strstr(&arbPtr[i], HTTP_HEADER_START_LINE);
+        len = strlen(HTTP_HEADER_START_LINE);
+        // validate that header string
+        if((strstr(&arbPtr[i+len], HTTP_HEADER_START_LINE) == NULL ||
+           (strstr(&arbPtr[i+len], HTTP_HEADER_START_LINE) > (const char*)buf)) && //
+            strstr(&arbPtr[i+len], HTTP_HEADER_CONTENT_TYPE) != NULL &&
+            strstr(&arbPtr[i+len], HTTP_HEADER_CONTENT_LEN) != NULL  &&
+            hdrPtr != NULL)
+        {
+            hdrFound = true;
+            break;
+        }
     }
-    if(http_response == NULL)
+    // calculate header length 
+    int hdrLen = (const char*) buf -hdrPtr;
+    // copy header 
+    memcpy(at_data_resp->buffer, (const uint8_t *) hdrPtr, hdrLen);
+    printf("[i = %d] This is the header\r\n%s\r\n", i, hdrPtr);
+    if(hdrFound == false)
     {
-        printf("[WIFI-MAN] copy failed: response pointer NULL!!\r\n");
+        printf("[WIFI-MAN] copy failed: HTTP header not found!!\r\n");
         return false;
     }
-    printf("before getting HTTP status line http_response = 0x%08X\n", http_response);
-    numChars = sprintf(msgPtr, "HTTP/1.1 %d %s\r\n", http_response->get_status_code(), 
-                                                     http_response->get_status_message().c_str());
-    msgPtr += numChars;
-    printf("before getting HTTP headers length\n");
-
-    int hdrsLen = http_response->get_headers_length();
-    printf("after getting HTTP headers length = %d\n", hdrsLen);
-    //print_memory_info();
-    if(hdrsLen <= 1)
-    {
-        printf("copy failed: Header Line = [%s]", msgPtr);
-        return false;
-    }
-    char * hdrField;
-    char * hdrValue;
-    for (size_t ix = 0; ix < hdrsLen; ix++) {
-        int sLen = http_response->get_headers_fields()[ix]->size()+1;
-        hdrField = new char [sLen];
-        std::strcpy (hdrField, http_response->get_headers_fields()[ix]->c_str());
-        hdrValue = new char [sLen];
-        std::strcpy (hdrValue, http_response->get_headers_values()[ix]->c_str());
-        numChars = sprintf(msgPtr, "%s: %s\r\n", hdrField, hdrValue);
-        delete hdrField;
-        delete hdrValue;
-        msgPtr += numChars;
-    }
-    numChars = sprintf(msgPtr, "\r\n");
-    msgPtr += numChars;
-    // print out generated header
-    printf("[WiFi MAN] generated response header:\n");
-    printf("%s\r\n", (char *)at_data_resp->buffer);
-    // calculate header length 
-    at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer);
+    at_data_resp->dataLen = hdrLen;
     return true;
 }
 
@@ -829,6 +811,14 @@
 void WiFiManager::body_callback(const char *at, uint32_t length) {    
     printf("\n Chunked response: Chunk %d : Total Bytes = %d\n", chunkNum , length);
     chunkNum++;
+    if(http_response == NULL)
+    {
+        printf("[WIFI-MAN] response pointer NULL!!\r\n");
+    }
+    else
+    {
+        printf("[WIFI-MAN] response pointer NULL not!!\r\n");
+    }
     sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
 }
 
@@ -1021,6 +1011,7 @@
             }
             //_wmutex.lock();
             http_response = https_request->send(http_req_cfg->body, bodyLen);
+            //https_request->send(http_req_cfg->body, bodyLen);
             //_wmutex.unlock();
         }
 #else