Fabrice Froehly / Mbed OS GuardRoom

Dependencies:   C12832 MMA7660 mbed-http

Fork of http-example by sandbox

Revision:
1:3bff14db67c7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/mbed-http/http_response.h	Thu Feb 16 11:13:40 2017 +0100
@@ -0,0 +1,90 @@
+#ifndef _MBED_HTTP_HTTP_RESPONSE
+#define _MBED_HTTP_HTTP_RESPONSE
+#include <string>
+#include <vector>
+#include "http_parser.h"
+
+using namespace std;
+
+class HttpResponse {
+public:
+    HttpResponse() {
+        status_code = 0;
+        concat_header_field = false;
+        concat_header_value = false;
+    }
+
+    void set_status(int a_status_code, string a_status_message) {
+        status_code = a_status_code;
+        status_message = a_status_message;
+    }
+
+    int get_status_code() {
+        return status_code;
+    }
+
+    string get_status_message() {
+        return status_message;
+    }
+
+    void set_header_field(string field) {
+        concat_header_value = false;
+
+        // headers can be chunked
+        if (concat_header_field) {
+            header_fields[header_fields.size() - 1] = header_fields[header_fields.size() - 1] + field;
+        }
+        else {
+            header_fields.push_back(field);
+        }
+
+        concat_header_field = true;
+    }
+
+    void set_header_value(string value) {
+        concat_header_field = false;
+
+        // headers can be chunked
+        if (concat_header_value) {
+            header_values[header_values.size() - 1] = header_values[header_values.size() - 1] + value;
+        }
+        else {
+            header_values.push_back(value);
+        }
+
+        concat_header_value = true;
+    }
+
+    size_t get_headers_length() {
+        return header_fields.size();
+    }
+
+    vector<string> get_headers_fields() {
+        return header_fields;
+    }
+
+    vector<string> get_headers_values() {
+        return header_values;
+    }
+
+    void set_body(string v) {
+        body = body + v;
+    }
+
+    string get_body() {
+        return body;
+    }
+
+private:
+    int status_code;
+    string status_message;
+
+    vector<string> header_fields;
+    vector<string> header_values;
+
+    bool concat_header_field;
+    bool concat_header_value;
+
+    string body;
+};
+#endif