mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
add support for "Expect: 100-continue"
This commit is contained in:
parent
23f9b52858
commit
c19eed0285
@ -34,6 +34,18 @@ namespace crow
|
||||
do_read();
|
||||
}
|
||||
|
||||
void handle_header()
|
||||
{
|
||||
// HTTP 1.1 Expect: 100-continue
|
||||
if (parser_.check_version(1, 1) && parser_.headers.count("expect") && parser_.headers["expect"] == "100-continue")
|
||||
{
|
||||
buffers_.clear();
|
||||
static std::string expect_100_continue = "HTTP/1.1 100 Continue\r\n\r\n";
|
||||
buffers_.emplace_back(expect_100_continue.data(), expect_100_continue.size());
|
||||
do_write();
|
||||
}
|
||||
}
|
||||
|
||||
void handle()
|
||||
{
|
||||
static std::unordered_map<int, std::string> statusCodes = {
|
||||
@ -61,13 +73,13 @@ namespace crow
|
||||
bool is_invalid_request = false;
|
||||
|
||||
request req = parser_.to_request();
|
||||
if (parser_.http_major == 1 && parser_.http_minor == 0)
|
||||
if (parser_.check_version(1, 0))
|
||||
{
|
||||
// HTTP/1.0
|
||||
if (!(req.headers.count("connection") && boost::iequals(req.headers["connection"],"Keep-Alive")))
|
||||
close_connection_ = true;
|
||||
}
|
||||
else if (parser_.http_major == 1 && parser_.http_minor == 1)
|
||||
else if (parser_.check_version(1, 1))
|
||||
{
|
||||
// HTTP/1.1
|
||||
if (req.headers.count("connection") && req.headers["connection"] == "close")
|
||||
|
13
parser.h
13
parser.h
@ -66,6 +66,7 @@ namespace crow
|
||||
boost::algorithm::to_lower(self->header_field);
|
||||
self->headers.emplace(std::move(self->header_field), std::move(self->header_value));
|
||||
}
|
||||
self->process_header();
|
||||
return 0;
|
||||
}
|
||||
static int on_body(http_parser* self_, const char* at, size_t length)
|
||||
@ -118,16 +119,26 @@ namespace crow
|
||||
body.clear();
|
||||
}
|
||||
|
||||
void process_header()
|
||||
{
|
||||
handler_->handle_header();
|
||||
}
|
||||
|
||||
void process_message()
|
||||
{
|
||||
handler_->handle();
|
||||
}
|
||||
|
||||
request to_request()
|
||||
request to_request() const
|
||||
{
|
||||
return request{(HTTPMethod)method, std::move(url), std::move(headers), std::move(body)};
|
||||
}
|
||||
|
||||
bool check_version(int major, int minor) const
|
||||
{
|
||||
return http_major == major && http_minor == minor;
|
||||
}
|
||||
|
||||
std::string url;
|
||||
int header_building_state = 0;
|
||||
std::string header_field;
|
||||
|
@ -241,7 +241,7 @@ TEST(server_handling_error_request)
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
//std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
server.stop();
|
||||
|
Loading…
Reference in New Issue
Block a user