fix old naming, check for host header

This commit is contained in:
ipknHama 2014-05-02 18:22:02 +09:00
parent 31d2e07bc2
commit 23f9b52858
4 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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_;
};

View File

@ -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()

View File

@ -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));
}