diff --git a/src/json_filter.cpp b/src/json_filter.cpp index 9d3eec2..25eb530 100644 --- a/src/json_filter.cpp +++ b/src/json_filter.cpp @@ -2,16 +2,23 @@ JsonFilter::JsonFilter() {} +__attribute__((always_inline)) inline bool Contains(std::string_view str, const std::string &val) { return str.find(val) != std::string::npos; } + void JsonFilter::doFilter(const HttpRequestPtr &req, FilterCallback &&fcb, FilterChainCallback &&fccb) { - std::string_view content_type = req->getHeader("Content-Type"); - if ((content_type == "application/json" || content_type == "*/*") && req->getHeader("Accept") == "application/json") //probably will need to change to contains() type function rather then equality check + std::string_view content_type = req->getHeader("content-type"); + std::string_view accept_header = req->getHeader("Accept"); + if (content_type == "applications/json") { - fccb(); - return; + if (Contains(accept_header, "*/*") || Contains(accept_header, "application/json")) + { + fccb(); + return; + } } + const auto &resp = HttpResponse::newHttpJsonResponse("Client must Accept JSON"); resp->setStatusCode(k406NotAcceptable); fcb(resp);