X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=parse.cpp;h=bec742b8897e850795d2720fc4ab79cdf27e2628;hp=c14b47fdad06fd6ce76cea3d8409aaf36400a6e1;hb=58dd753c464d917dc446e2cbb4c01fd750d4eb87;hpb=9bb20b7dd0bcea9de1daf4cac29263d74924ce5a diff --git a/parse.cpp b/parse.cpp index c14b47f..bec742b 100644 --- a/parse.cpp +++ b/parse.cpp @@ -3,6 +3,7 @@ #include #include +#include "log.h" #include "parse.h" using namespace std; @@ -55,6 +56,32 @@ vector split_lines(const string &str) return ret; } +unordered_multimap extract_headers(const vector &lines, const string &log_context) +{ + unordered_multimap parameters; + for (size_t i = 1; i < lines.size(); ++i) { + size_t split = lines[i].find(":"); + if (split == string::npos) { + log(WARNING, "[%s] Ignoring malformed HTTP response line '%s'", + log_context.c_str(), lines[i].c_str()); + continue; + } + + string key(lines[i].begin(), lines[i].begin() + split); + + // Skip any spaces after the colon. + do { + ++split; + } while (split < lines[i].size() && (lines[i][split] == ' ' || lines[i][split] == '\t')); + + string value(lines[i].begin() + split, lines[i].end()); + + parameters.insert(make_pair(key, value)); + } + + return parameters; +} + #define MAX_REQUEST_SIZE 16384 /* 16 kB. */ RequestParseStatus wait_for_double_newline(string *existing_data, const char *new_data, size_t new_data_size) @@ -73,7 +100,7 @@ RequestParseStatus wait_for_double_newline(string *existing_data, const char *ne const char *ptr = reinterpret_cast( memmem(existing_data->data() + start_at, existing_data->size() - start_at, "\r\n\r\n", 4)); - if (ptr == NULL) { + if (ptr == nullptr) { return RP_NOT_FINISHED_YET; } if (ptr != existing_data->data() + existing_data->size() - 4) {