Better naming for initial request HTTP state
STATE_EXPECT_METHOD -> STATE_EXPECT_START_LINE
This commit is contained in:
parent
0c068c3c78
commit
5e456e3993
|
|
@ -125,7 +125,7 @@ HttpServerConnection::HttpServerConnection(
|
|||
int sock, const IpAddress& remote_addr, uint16_t remote_port,
|
||||
size_t recv_buf_len)
|
||||
: TcpConnection(sock, remote_addr, remote_port, recv_buf_len),
|
||||
m_state(STATE_EXPECT_METHOD)
|
||||
m_state(STATE_EXPECT_START_LINE)
|
||||
{
|
||||
} /* HttpServerConnection::HttpServerConnection */
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ int HttpServerConnection::onDataReceived(void *buf, int count)
|
|||
|
||||
while (data.size() > data_pos)
|
||||
{
|
||||
if (m_state == STATE_EXPECT_METHOD)
|
||||
if (m_state == STATE_EXPECT_START_LINE)
|
||||
{
|
||||
size_t eol = data.find("\r\n", data_pos);
|
||||
size_t len = eol;
|
||||
|
|
@ -243,7 +243,7 @@ int HttpServerConnection::onDataReceived(void *buf, int count)
|
|||
if (eol != std::string::npos)
|
||||
{
|
||||
data_pos += 2;
|
||||
handleMethod();
|
||||
handleStartLine();
|
||||
m_row.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ int HttpServerConnection::onDataReceived(void *buf, int count)
|
|||
{
|
||||
requestReceived(this, m_req);
|
||||
m_req.clear();
|
||||
m_state = STATE_EXPECT_METHOD;
|
||||
m_state = STATE_EXPECT_START_LINE;
|
||||
}
|
||||
|
||||
return count;
|
||||
|
|
@ -288,11 +288,11 @@ int HttpServerConnection::onDataReceived(void *buf, int count)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void HttpServerConnection::handleMethod(void)
|
||||
void HttpServerConnection::handleStartLine(void)
|
||||
{
|
||||
std::istringstream is(m_row);
|
||||
std::string protocol;
|
||||
if (!(is >> m_req.method >> m_req.uri >> protocol >> std::ws))
|
||||
if (!(is >> m_req.method >> m_req.target >> protocol >> std::ws))
|
||||
{
|
||||
std::cerr << "*** ERROR: Could not parse HTTP header" << std::endl;
|
||||
disconnect();
|
||||
|
|
@ -310,7 +310,7 @@ void HttpServerConnection::handleMethod(void)
|
|||
is.clear();
|
||||
is.str(protocol.substr(5));
|
||||
char dot;
|
||||
if (!(is >> m_req.proto_major >> dot >> m_req.proto_minor >> std::ws) ||
|
||||
if (!(is >> m_req.ver_major >> dot >> m_req.ver_minor >> std::ws) ||
|
||||
(dot != '.'))
|
||||
{
|
||||
std::cerr << "*** ERROR: Illegal protocol version specification \""
|
||||
|
|
@ -319,13 +319,13 @@ void HttpServerConnection::handleMethod(void)
|
|||
return;
|
||||
}
|
||||
|
||||
//std::cout << "### HttpServerConnection::handleMethod: method="
|
||||
// << m_req.method << " uri=" << m_req.uri
|
||||
// << " version=" << m_req.proto_major << "."
|
||||
// << m_req.proto_minor
|
||||
//std::cout << "### HttpServerConnection::handleStartLine: method="
|
||||
// << m_req.method << " target=" << m_req.target
|
||||
// << " version=" << m_req.ver_major << "."
|
||||
// << m_req.ver_minor
|
||||
// << std::endl;
|
||||
m_state = STATE_EXPECT_HEADER;
|
||||
} /* HttpServerConnection::handleMethod */
|
||||
} /* HttpServerConnection::handleStartLine */
|
||||
|
||||
|
||||
void HttpServerConnection::handleHeader(void)
|
||||
|
|
@ -357,7 +357,7 @@ void HttpServerConnection::handleHeader(void)
|
|||
}
|
||||
std::string value(m_row.substr(value_begin, value_end-value_begin+1));
|
||||
|
||||
//std::cout << "### HttpServerConnection::handleMethod: key="
|
||||
//std::cout << "### HttpServerConnection::handleStartLine: key="
|
||||
// << key << " value=" << value << std::endl;
|
||||
|
||||
m_req.headers[key] = value;
|
||||
|
|
|
|||
|
|
@ -131,9 +131,9 @@ class HttpServerConnection : public TcpConnection
|
|||
struct Request
|
||||
{
|
||||
std::string method;
|
||||
std::string uri;
|
||||
unsigned proto_major;
|
||||
unsigned proto_minor;
|
||||
std::string target;
|
||||
unsigned ver_major;
|
||||
unsigned ver_minor;
|
||||
Headers headers;
|
||||
|
||||
Request(void)
|
||||
|
|
@ -144,10 +144,10 @@ class HttpServerConnection : public TcpConnection
|
|||
void clear(void)
|
||||
{
|
||||
method.clear();
|
||||
uri.clear();
|
||||
target.clear();
|
||||
headers.clear();
|
||||
proto_major = 0;
|
||||
proto_minor = 0;
|
||||
ver_major = 0;
|
||||
ver_minor = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -299,7 +299,7 @@ class HttpServerConnection : public TcpConnection
|
|||
|
||||
private:
|
||||
enum State {
|
||||
STATE_DISCONNECTED, STATE_EXPECT_METHOD, STATE_EXPECT_HEADER,
|
||||
STATE_DISCONNECTED, STATE_EXPECT_START_LINE, STATE_EXPECT_HEADER,
|
||||
STATE_EXPECT_PAYLOAD, STATE_REQ_COMPLETE
|
||||
};
|
||||
//static const uint32_t DEFAULT_MAX_FRAME_SIZE = 1024 * 1024; // 1MB
|
||||
|
|
@ -336,7 +336,7 @@ class HttpServerConnection : public TcpConnection
|
|||
|
||||
HttpServerConnection(const HttpServerConnection&);
|
||||
HttpServerConnection& operator=(const HttpServerConnection&);
|
||||
void handleMethod(void);
|
||||
void handleStartLine(void);
|
||||
void handleHeader(void);
|
||||
void onSendBufferFull(bool is_full);
|
||||
void disconnectCleanup(void);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
void requestReceived(Async::HttpServerConnection *con,
|
||||
Async::HttpServerConnection::Request& req)
|
||||
{
|
||||
std::cout << "--- " << req.method << " " << req.uri << std::endl;
|
||||
std::cout << "--- " << req.method << " " << req.target << std::endl;
|
||||
|
||||
Async::HttpServerConnection::Response res;
|
||||
if ((req.method != "GET") && (req.method != "HEAD"))
|
||||
|
|
@ -20,9 +20,9 @@ void requestReceived(Async::HttpServerConnection *con,
|
|||
std::ostringstream os;
|
||||
os << "{"
|
||||
<< "\"method\":\"" << req.method << "\","
|
||||
<< "\"uri\":\"" << req.uri << "\","
|
||||
<< "\"client-proto-major\":" << req.proto_major << ","
|
||||
<< "\"client-proto-minor\":" << req.proto_minor << ","
|
||||
<< "\"target\":\"" << req.target << "\","
|
||||
<< "\"client-proto-major\":" << req.ver_major << ","
|
||||
<< "\"client-proto-minor\":" << req.ver_minor << ","
|
||||
<< "\"headers\":{";
|
||||
Async::HttpServerConnection::Headers::const_iterator it;
|
||||
for (it=req.headers.begin(); it!=req.headers.end(); ++it)
|
||||
|
|
|
|||
|
|
@ -598,7 +598,7 @@ void Reflector::onTalkerUpdated(uint32_t tg, ReflectorClient* old_talker,
|
|||
void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
||||
Async::HttpServerConnection::Request& req)
|
||||
{
|
||||
//std::cout << "### " << req.method << " " << req.uri << std::endl;
|
||||
//std::cout << "### " << req.method << " " << req.target << std::endl;
|
||||
|
||||
Async::HttpServerConnection::Response res;
|
||||
if ((req.method != "GET") && (req.method != "HEAD"))
|
||||
|
|
@ -610,7 +610,7 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||
return;
|
||||
}
|
||||
|
||||
if (req.uri != "/status")
|
||||
if (req.target != "/status")
|
||||
{
|
||||
res.setCode(404);
|
||||
res.setContent("application/json",
|
||||
|
|
@ -622,7 +622,7 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||
std::ostringstream os;
|
||||
os << "{"
|
||||
//<< "\"method\":\"" << req.method << "\","
|
||||
//<< "\"uri\":\"" << req.uri << "\","
|
||||
//<< "\"target\":\"" << req.target << "\","
|
||||
//<< "\"headers\":{"
|
||||
;
|
||||
//Async::HttpServerConnection::Headers::const_iterator it;
|
||||
|
|
|
|||
Loading…
Reference in New Issue