summaryrefslogtreecommitdiff
path: root/src/HttpResponse.cpp
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-09-17 10:26:22 -0600
committercflip <cflip@cflip.net>2022-09-17 11:12:16 -0600
commit105ebbce53ce3e28890c08961168dd21760676b9 (patch)
tree30ec3fc2559fe085da0610818b0fd01efd34e191 /src/HttpResponse.cpp
parentac12ef846b343849317539c84258ab0c5e6b542f (diff)
Pass HTTP headers from CGI output into our HttpResponse class
Diffstat (limited to 'src/HttpResponse.cpp')
-rw-r--r--src/HttpResponse.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/HttpResponse.cpp b/src/HttpResponse.cpp
index 2d69583..c07178f 100644
--- a/src/HttpResponse.cpp
+++ b/src/HttpResponse.cpp
@@ -2,6 +2,32 @@
#include <sstream>
+void HttpResponse::add_headers_and_content(const std::string& input)
+{
+ bool is_parsing_headers = true;
+
+ size_t pos = 0;
+ std::string s = input;
+ std::string line;
+ while ((pos = s.find("\n")) != std::string::npos) {
+ line = s.substr(0, pos + 1);
+
+ if (is_parsing_headers) {
+ size_t delim_pos = 0;
+ if ((delim_pos = line.find(":")) != std::string::npos) {
+ std::string header_key = s.substr(0, delim_pos);
+ std::string header_value = s.substr(delim_pos + 2, s.find("\n") - delim_pos - 2);
+ m_headers[header_key] = header_value;
+ } else {
+ is_parsing_headers = false;
+ }
+ } else {
+ m_content += line;
+ }
+ s.erase(0, pos + 1);
+ }
+}
+
static std::string status_code_string(HttpStatusCode status_code)
{
switch (status_code) {