diff options
author | Pixel <pixel@nobis-crew.org> | 2011-11-15 07:31:02 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2011-11-15 07:31:02 -0800 |
commit | 7e0f18a57671b67ae575803e947e56bb4cf711b7 (patch) | |
tree | 1ebf9c8369eddb3c212e248ba386748e4c8a2be7 /src | |
parent | b396ad5dd5880681a79bd2d33b46ebf90f3c5028 (diff) |
Initial parsing of the Http request should now be there.
Diffstat (limited to 'src')
-rw-r--r-- | src/HttpServer.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 35bd414..b35b7c2 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -1,3 +1,5 @@ +#include <map> + #include "Http.h" #include "HttpServer.h" #include "Socket.h" @@ -58,6 +60,9 @@ bool Balau::HttpWorker::handleClient() { String line; bool gotFirst = false; int method = -1; + String url; + String HttpVersion; + std::map<String, String> HttpHeaders; // read client's request do { @@ -106,8 +111,45 @@ bool Balau::HttpWorker::handleClient() { send400(); return false; } + + url = line.extract(urlBegin, urlEnd); + + int httpBegin = urlEnd + 2; + + if ((httpBegin + 5) >= line.strlen()) { + send400(); + return false; + } + + if ((line[httpBegin + 0] == 'H') && + (line[httpBegin + 1] == 'T') && + (line[httpBegin + 2] == 'T') && + (line[httpBegin + 3] == 'P') && + (line[httpBegin + 4] == '/')) { + HttpVersion = line.extract(httpBegin + 5); + } else { + send400(); + return false; + } + + if ((HttpVersion != "1.0") && (HttpVersion != "1.1")) { + send400(); + return false; + } } else { // parse HTTP header. + int colon = line.strchr(':'); + if (colon <= 0) { + send400(); + return false; + } + + String key = line.extract(0, colon - 1); + String value = line.extract(colon + 1); + + value.trim(); + + HttpHeaders[key] = value; } } while(true); |