+HTTPHeaderMultimap extract_headers(const vector<string> &lines, const string &log_context)
+{
+ HTTPHeaderMultimap 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;
+}
+