From 7e0f18a57671b67ae575803e947e56bb4cf711b7 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 15 Nov 2011 07:31:02 -0800 Subject: Initial parsing of the Http request should now be there. --- src/HttpServer.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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 + #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 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); -- cgit v1.2.3