Esempio n. 1
0
	void OnDataReady()
	{
		if (InternalState == HTTP_SERVE_RECV_POSTDATA)
		{
			postdata.append(recvq);
			if (postdata.length() >= postsize)
				ServeData();
		}
		else
		{
			reqbuffer.append(recvq);

			if (reqbuffer.length() >= 8192)
			{
				ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "m_httpd dropped connection due to an oversized request buffer");
				reqbuffer.clear();
				SetError("Buffer");
			}

			if (InternalState == HTTP_SERVE_WAIT_REQUEST)
				CheckRequestBuffer();
		}
	}
Esempio n. 2
0
bool Connection::AddBuffer(const std::string &a)
{
	if (!a.length())
	{
		/* how is this possible .. */
		return true;
	}
	
	if (State == HTTP_RECV_REQBODY)
	{
		/*
		 * Note!
		 *
		 * Don't be clever here, we *must* only take what we can to the request body
		 * (i.e. NO MORE than RequestBodyLength!). It would be naughty to accept any
		 * more than content-length bytes for the request body, primarily
		 * thanks to pipelining. So, we take what we can, and shove the rest in the request buffer.
		 */
		unsigned int remains = RequestBodyLength - RequestBody.length();
		
		if (remains < a.length())
		{
			RequestBody.append(a.begin(), a.begin() + remains);
			// The rest of this goes into the request buffer
			requestbuf.append(a);
		}
		else
			RequestBody.append(a);
		
		if (RequestBody.length() == RequestBodyLength)
		{
			// Done reading the request body
			ServerInstance->Log(DEBUG, "Request body: %s", RequestBody.c_str());
			ServerInstance->Log(DEBUG, "Finished reading request body (%d bytes). Serving request.", RequestBodyLength);
			ServeData();
			return true;
		}
	}
	else
	{
		/* We can get data for a future request at any time, and that
		 * is what we're doing here. We only trigger the check for a
		 * new request if we're waiting for one. */
		
		int nspos = requestbuf.length();
		
		requestbuf.append(a);

		if (State == HTTP_WAIT_REQUEST)
			this->CheckRequest(nspos);		
	}

	if (requestbuf.length() > 5120)
	{
		// XXX arbitrary limit; needs discussion of a proper default
		ServerInstance->Log(DEBUG, "Too much data in buffer; dropping");
		return false;
	}

	return true;
}