diff options
-rw-r--r-- | http_connection.h | 14 | ||||
-rw-r--r-- | http_server.h | 3 | ||||
-rw-r--r-- | test.py | 2 | ||||
-rw-r--r-- | unittest.cpp | 1 |
4 files changed, 14 insertions, 6 deletions
diff --git a/http_connection.h b/http_connection.h index 4d39641..5da294d 100644 --- a/http_connection.h +++ b/http_connection.h @@ -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 diff --git a/http_server.h b/http_server.h index aa3124e..6cf8f4f 100644 --- a/http_server.h +++ b/http_server.h @@ -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_; }; @@ -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() diff --git a/unittest.cpp b/unittest.cpp index 58e0639..40903c5 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -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)); } |