mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Reformatting using AStyle
This commit is contained in:
@@ -8,97 +8,107 @@ SETUP_LOG (HTTPRequest)
|
||||
|
||||
// Logic to handle incoming HTTP reqests
|
||||
|
||||
void HTTPRequest::reset()
|
||||
void HTTPRequest::reset ()
|
||||
{
|
||||
mHeaders.clear();
|
||||
sRequestBody.clear();
|
||||
sAuthorization.clear();
|
||||
iDataSize = 0;
|
||||
bShouldClose = true;
|
||||
eState = await_request;
|
||||
mHeaders.clear ();
|
||||
sRequestBody.clear ();
|
||||
sAuthorization.clear ();
|
||||
iDataSize = 0;
|
||||
bShouldClose = true;
|
||||
eState = await_request;
|
||||
}
|
||||
|
||||
HTTPRequestAction HTTPRequest::requestDone(bool forceClose)
|
||||
HTTPRequestAction HTTPRequest::requestDone (bool forceClose)
|
||||
{
|
||||
if (forceClose || bShouldClose)
|
||||
return haCLOSE_CONN;
|
||||
reset();
|
||||
return haREAD_LINE;
|
||||
if (forceClose || bShouldClose)
|
||||
return haCLOSE_CONN;
|
||||
|
||||
reset ();
|
||||
return haREAD_LINE;
|
||||
}
|
||||
|
||||
std::string HTTPRequest::getReplyHeaders(bool forceClose)
|
||||
std::string HTTPRequest::getReplyHeaders (bool forceClose)
|
||||
{
|
||||
if (forceClose || bShouldClose)
|
||||
return "Connection: close\r\n";
|
||||
else
|
||||
return "Connection: Keep-Alive\r\n";
|
||||
if (forceClose || bShouldClose)
|
||||
return "Connection: close\r\n";
|
||||
else
|
||||
return "Connection: Keep-Alive\r\n";
|
||||
}
|
||||
|
||||
HTTPRequestAction HTTPRequest::consume(boost::asio::streambuf& buf)
|
||||
HTTPRequestAction HTTPRequest::consume (boost::asio::streambuf& buf)
|
||||
{
|
||||
std::string line;
|
||||
std::istream is(&buf);
|
||||
std::getline(is, line);
|
||||
boost::trim(line);
|
||||
std::string line;
|
||||
std::istream is (&buf);
|
||||
std::getline (is, line);
|
||||
boost::trim (line);
|
||||
|
||||
// WriteLog (lsTRACE, HTTPRequest) << "HTTPRequest line: " << line;
|
||||
// WriteLog (lsTRACE, HTTPRequest) << "HTTPRequest line: " << line;
|
||||
|
||||
if (eState == await_request)
|
||||
{ // VERB URL PROTO
|
||||
if (line.empty())
|
||||
return haREAD_LINE;
|
||||
sRequest = line;
|
||||
bShouldClose = sRequest.find("HTTP/1.1") == std::string::npos;
|
||||
if (eState == await_request)
|
||||
{
|
||||
// VERB URL PROTO
|
||||
if (line.empty ())
|
||||
return haREAD_LINE;
|
||||
|
||||
eState = await_header;
|
||||
return haREAD_LINE;
|
||||
}
|
||||
sRequest = line;
|
||||
bShouldClose = sRequest.find ("HTTP/1.1") == std::string::npos;
|
||||
|
||||
if (eState == await_header)
|
||||
{ // HEADER_NAME: HEADER_BODY
|
||||
if (line.empty()) // empty line or bare \r
|
||||
{
|
||||
if (iDataSize == 0)
|
||||
{ // no body
|
||||
eState = do_request;
|
||||
return haDO_REQUEST;
|
||||
}
|
||||
eState = getting_body;
|
||||
return haREAD_RAW;
|
||||
}
|
||||
size_t colon = line.find(':');
|
||||
if (colon != std::string::npos)
|
||||
{
|
||||
std::string headerName = line.substr(0, colon);
|
||||
boost::trim(headerName);
|
||||
boost::to_lower(headerName);
|
||||
eState = await_header;
|
||||
return haREAD_LINE;
|
||||
}
|
||||
|
||||
std::string headerValue = line.substr(colon+1);
|
||||
boost::trim(headerValue);
|
||||
if (eState == await_header)
|
||||
{
|
||||
// HEADER_NAME: HEADER_BODY
|
||||
if (line.empty ()) // empty line or bare \r
|
||||
{
|
||||
if (iDataSize == 0)
|
||||
{
|
||||
// no body
|
||||
eState = do_request;
|
||||
return haDO_REQUEST;
|
||||
}
|
||||
|
||||
mHeaders[headerName] += headerValue;
|
||||
eState = getting_body;
|
||||
return haREAD_RAW;
|
||||
}
|
||||
|
||||
if (headerName == "connection")
|
||||
{
|
||||
boost::to_lower(headerValue);
|
||||
if ((headerValue == "keep-alive") || (headerValue == "keepalive"))
|
||||
bShouldClose = false;
|
||||
if (headerValue == "close")
|
||||
bShouldClose = true;
|
||||
}
|
||||
size_t colon = line.find (':');
|
||||
|
||||
if (headerName == "content-length")
|
||||
iDataSize = boost::lexical_cast<int>(headerValue);
|
||||
if (colon != std::string::npos)
|
||||
{
|
||||
std::string headerName = line.substr (0, colon);
|
||||
boost::trim (headerName);
|
||||
boost::to_lower (headerName);
|
||||
|
||||
if (headerName == "authorization")
|
||||
sAuthorization = headerValue;
|
||||
}
|
||||
std::string headerValue = line.substr (colon + 1);
|
||||
boost::trim (headerValue);
|
||||
|
||||
return haREAD_LINE;
|
||||
}
|
||||
mHeaders[headerName] += headerValue;
|
||||
|
||||
assert(false);
|
||||
return haERROR;
|
||||
if (headerName == "connection")
|
||||
{
|
||||
boost::to_lower (headerValue);
|
||||
|
||||
if ((headerValue == "keep-alive") || (headerValue == "keepalive"))
|
||||
bShouldClose = false;
|
||||
|
||||
if (headerValue == "close")
|
||||
bShouldClose = true;
|
||||
}
|
||||
|
||||
if (headerName == "content-length")
|
||||
iDataSize = boost::lexical_cast<int> (headerValue);
|
||||
|
||||
if (headerName == "authorization")
|
||||
sAuthorization = headerValue;
|
||||
}
|
||||
|
||||
return haREAD_LINE;
|
||||
}
|
||||
|
||||
assert (false);
|
||||
return haERROR;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user