diff --git a/include/crow/http_connection.h b/include/crow/http_connection.h index e93139217..e28c9183e 100644 --- a/include/crow/http_connection.h +++ b/include/crow/http_connection.h @@ -113,9 +113,16 @@ namespace crow // if no route is found for the request method, return the response without parsing or processing anything further. if (!routing_handle_result_->rule_index) { - parser_.done(); - need_to_call_after_handlers_ = true; - complete_request(); + if (req_.method == HTTPMethod::Options) + { + need_to_call_after_handlers_ = true; + } + else + { + parser_.done(); + need_to_call_after_handlers_ = true; // Not sure if the order of this and the above line matters + complete_request(); + } } } @@ -180,7 +187,11 @@ namespace crow CROW_LOG_INFO << "Request: " << utility::lexical_cast(adaptor_.remote_endpoint()) << " " << this << " HTTP/" << (char)(req_.http_ver_major + '0') << "." << (char)(req_.http_ver_minor + '0') << ' ' << method_name(req_.method) << " " << req_.url; - need_to_call_after_handlers_ = false; + if (req_.method != HTTPMethod::Options) + { + need_to_call_after_handlers_ = false; + } + if (!is_invalid_request) { res.complete_request_handler_ = nullptr; diff --git a/include/crow/middlewares/cors.h b/include/crow/middlewares/cors.h index 15e7d4213..f490a6209 100644 --- a/include/crow/middlewares/cors.h +++ b/include/crow/middlewares/cors.h @@ -130,16 +130,13 @@ namespace crow bool origin_set = false; - if (req.method != HTTPMethod::Options) + if (allow_credentials_) { - if (allow_credentials_) + set_header_no_override("Access-Control-Allow-Credentials", "true", res); + if (origin_ == "*") { - set_header_no_override("Access-Control-Allow-Credentials", "true", res); - if (origin_ == "*") - { - set_header_no_override("Access-Control-Allow-Origin", req.get_header_value("Origin"), res); - origin_set = true; - } + set_header_no_override("Access-Control-Allow-Origin", req.get_header_value("Origin"), res); + origin_set = true; } }