Better HTTP version handling

This commit is contained in:
Tobias Blomberg 2019-10-05 22:47:00 +02:00
parent 4721815b8e
commit 0c068c3c78
4 changed files with 36 additions and 5 deletions

View File

@ -299,16 +299,31 @@ void HttpServerConnection::handleMethod(void)
return;
}
if (protocol != "HTTP/1.1")
if (protocol.substr(0, 5) != "HTTP/")
{
std::cerr << "*** ERROR: Unsupported protocol \""
std::cerr << "*** ERROR: Illegal protocol specification string \""
<< protocol << "\"" << std::endl;
disconnect();
return;
}
is.clear();
is.str(protocol.substr(5));
char dot;
if (!(is >> m_req.proto_major >> dot >> m_req.proto_minor >> std::ws) ||
(dot != '.'))
{
std::cerr << "*** ERROR: Illegal protocol version specification \""
<< protocol << "\"" << std::endl;
disconnect();
return;
}
//std::cout << "### HttpServerConnection::handleMethod: method="
// << m_req.method << " uri=" << m_req.uri << std::endl;
// << m_req.method << " uri=" << m_req.uri
// << " version=" << m_req.proto_major << "."
// << m_req.proto_minor
// << std::endl;
m_state = STATE_EXPECT_HEADER;
} /* HttpServerConnection::handleMethod */

View File

@ -132,9 +132,23 @@ class HttpServerConnection : public TcpConnection
{
std::string method;
std::string uri;
unsigned proto_major;
unsigned proto_minor;
Headers headers;
void clear(void) { method.clear(); uri.clear(); headers.clear(); }
Request(void)
{
clear();
}
void clear(void)
{
method.clear();
uri.clear();
headers.clear();
proto_major = 0;
proto_minor = 0;
}
};
class Response

View File

@ -21,6 +21,8 @@ void requestReceived(Async::HttpServerConnection *con,
os << "{"
<< "\"method\":\"" << req.method << "\","
<< "\"uri\":\"" << req.uri << "\","
<< "\"client-proto-major\":" << req.proto_major << ","
<< "\"client-proto-minor\":" << req.proto_minor << ","
<< "\"headers\":{";
Async::HttpServerConnection::Headers::const_iterator it;
for (it=req.headers.begin(); it!=req.headers.end(); ++it)

View File

@ -8,7 +8,7 @@ QTEL=1.2.4
LIBECHOLIB=1.3.3
# Version for the Async library
LIBASYNC=1.6.0.99.2-reflector_tg
LIBASYNC=1.6.0.99.3-reflector_tg
# SvxLink versions
SVXLINK=1.7.99.6-reflector_tg