- if ((InternalState == HTTP_SERVE_WAIT_REQUEST) && (request_type == "POST"))
- {
- /* Do we need to fetch postdata? */
- postdata.clear();
- InternalState = HTTP_SERVE_RECV_POSTDATA;
- std::string header_item;
- while (headers >> header_item)
- {
- if (header_item == "Content-Length:")
- {
- headers >> header_item;
- postsize = atoi(header_item.c_str());
- }
- }
- if (!postsize)
- {
- InternalState = HTTP_SERVE_SEND_DATA;
- SendHeaders(0, 400, "");
- Timeout = new HttpServerTimeout(this, Instance->SE);
- Instance->Timers->AddTimer(Timeout);
- }
- else
- {
- std::string::size_type x = headers.str().find("\r\n\r\n");
- postdata = headers.str().substr(x+4, headers.str().length());
- /* Get content length and store */
- if (postdata.length() >= postsize)
- ServeData();
- }
- }
- else if (InternalState == HTTP_SERVE_RECV_POSTDATA)
- {
- /* Add postdata, once we have it all, send the event */
- postdata.append(data);
- if (postdata.length() >= postsize)
- ServeData();
- }
- else
+ void CheckRequestBuffer()
+ {
+ std::string::size_type reqend = reqbuffer.find("\r\n\r\n");
+ if (reqend == std::string::npos)
+ return;
+
+ // We have the headers; parse them all
+ std::string::size_type hbegin = 0, hend;
+ while ((hend = reqbuffer.find("\r\n", hbegin)) != std::string::npos)
+ {
+ if (hbegin == hend)
+ break;
+
+ if (request_type.empty())
+ {
+ std::istringstream cheader(std::string(reqbuffer, hbegin, hend - hbegin));
+ cheader >> request_type;
+ cheader >> uri;
+ cheader >> http_version;
+
+ if (request_type.empty() || uri.empty() || http_version.empty())