http: Allow retrieving other headers.

Such as range request headers, accept headers, cookies, etc.
This commit is contained in:
Unknown W. Brackets committed 2016-05-26 18:16:39 -07:00
1 parent 41e7d3ecde
commit 1cc49f3be4
4 files changed
+31 -6

No files matched your search

+15 -1
View File
@@ -1,5 +1,6 @@
#include "net/http_headers.h"
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
@@ -40,6 +41,15 @@ bool RequestHeader::GetParamValue(const char *param_name, std::string *value) co
return false;
}
bool RequestHeader::GetOther(const char *name, std::string *value) const {
auto it = other.find(name);
if (it != other.end()) {
*value = it->second;
return true;
}
return false;
}
// Intended to be a mad fast parser. It's not THAT fast currently, there's still
// things to optimize, but meh.
int RequestHeader::ParseHttpHeader(const char *buffer) {
@@ -57,7 +67,7 @@ int RequestHeader::ParseHttpHeader(const char *buffer) {
buffer += 5;
} else {
method = UNSUPPORTED;
status = 501;
status = 405;
return -1;
}
SkipSpace(&buffer);
@@ -117,6 +127,10 @@ int RequestHeader::ParseHttpHeader(const char *buffer) {
} else if (!strncasecmp(key, "Content-Length", key_len)) {
content_length = atoi(buffer);
ILOG("Content-Length: %i", (int)content_length);
} else {
std::string key_str(key, key_len);
std::transform(key_str.begin(), key_str.end(), key_str.begin(), tolower);
other[key_str] = buffer;
}
return 0;