mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
fix old naming, check for host header
This commit is contained in:
parent
31d2e07bc2
commit
23f9b52858
@ -58,6 +58,8 @@ namespace crow
|
||||
{503, "HTTP/1.1 503 Service Unavailable\r\n"},
|
||||
};
|
||||
|
||||
bool is_invalid_request = false;
|
||||
|
||||
request req = parser_.to_request();
|
||||
if (parser_.http_major == 1 && parser_.http_minor == 0)
|
||||
{
|
||||
@ -65,14 +67,22 @@ namespace crow
|
||||
if (!(req.headers.count("connection") && boost::iequals(req.headers["connection"],"Keep-Alive")))
|
||||
close_connection_ = true;
|
||||
}
|
||||
else
|
||||
else if (parser_.http_major == 1 && parser_.http_minor == 1)
|
||||
{
|
||||
// HTTP/1.1
|
||||
if (req.headers.count("connection") && req.headers["connection"] == "close")
|
||||
close_connection_ = true;
|
||||
if (!req.headers.count("host"))
|
||||
{
|
||||
is_invalid_request = true;
|
||||
res = response(400);
|
||||
}
|
||||
}
|
||||
|
||||
res = handler_->handle(req);
|
||||
if (!is_invalid_request)
|
||||
{
|
||||
res = handler_->handle(req);
|
||||
}
|
||||
|
||||
CROW_LOG_INFO << "HTTP/" << parser_.http_major << "." << parser_.http_minor << ' '
|
||||
<< method_name(req.method) << " " << req.url
|
||||
|
@ -69,8 +69,7 @@ namespace crow
|
||||
boost::asio::signal_set signals_;
|
||||
|
||||
Handler* handler_;
|
||||
|
||||
uint16_t concurrency_ = {1};
|
||||
uint16_t concurrency_{1};
|
||||
std::string server_name_ = "Crow/0.1";
|
||||
uint16_t port_;
|
||||
};
|
||||
|
2
test.py
2
test.py
@ -1,6 +1,6 @@
|
||||
import urllib
|
||||
assert "Hello World!" == urllib.urlopen('http://localhost:18080').read()
|
||||
assert "About Flask example." == urllib.urlopen('http://localhost:18080/about').read()
|
||||
assert "About Crow example." == urllib.urlopen('http://localhost:18080/about').read()
|
||||
assert 404 == urllib.urlopen('http://localhost:18080/list').getcode()
|
||||
assert "3 bottles of beer!" == urllib.urlopen('http://localhost:18080/hello/3').read()
|
||||
assert "100 bottles of beer!" == urllib.urlopen('http://localhost:18080/hello/100').read()
|
||||
|
@ -280,7 +280,6 @@ TEST(multi_server)
|
||||
for(auto ch:sendmsg)
|
||||
{
|
||||
char buf[1] = {ch};
|
||||
std::cerr << ch << '(' << (int)ch<<')'<<std::endl;
|
||||
c.send(asio::buffer(buf));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user