fix the problem http request with '\0' and fixx query string in url

Fork of mbed-http by sandbox

Revision:
4:539df159e058
Parent:
3:8a6b003e3874
Child:
7:2e3eedb9ca5c
--- a/source/http_response.h	Thu Feb 23 13:28:07 2017 +0100
+++ b/source/http_response.h	Thu Feb 23 13:50:43 2017 +0100
@@ -31,6 +31,14 @@
         concat_header_value = false;
         expected_content_length = 0;
         body_length = 0;
+        body_offset = 0;
+        body = NULL;
+    }
+
+    ~HttpResponse() {
+        if (body != NULL) {
+            free(body);
+        }
     }
 
     void set_status(int a_status_code, string a_status_message) {
@@ -96,18 +104,34 @@
         return header_values;
     }
 
-    void set_body(string v) {
-        body = body + v;
+    void set_body(const char *at, size_t length) {
+        // only malloc when this fn is called, so we don't alloc when body callback's are enabled
+        if (body == NULL) {
+            body = (char*)malloc(expected_content_length);
+        }
+
+        memcpy(body + body_offset, at, length);
+
+        body_offset += length;
     }
 
-    string get_body() {
-        return body;
+    void* get_body() {
+        return (void*)body;
+    }
+
+    string get_body_as_string() {
+        string s(body, body_offset);
+        return s;
     }
 
     void increase_body_length(size_t length) {
         body_length += length;
     }
 
+    size_t get_body_length() {
+        return body_offset;
+    }
+
     bool is_body_complete() {
         return body_length == expected_content_length;
     }
@@ -134,7 +158,8 @@
 
     size_t expected_content_length;
 
-    string body;
+    char * body;
     size_t body_length;
+    size_t body_offset;
 };
 #endif