mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-18 09:02:14 +11:00
🐛 fixed Json Filter
This commit is contained in:
parent
ea35a04b66
commit
6402ad300c
1 changed files with 11 additions and 4 deletions
|
|
@ -2,16 +2,23 @@
|
||||||
|
|
||||||
JsonFilter::JsonFilter() {}
|
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,
|
void JsonFilter::doFilter(const HttpRequestPtr &req,
|
||||||
FilterCallback &&fcb,
|
FilterCallback &&fcb,
|
||||||
FilterChainCallback &&fccb)
|
FilterChainCallback &&fccb)
|
||||||
{
|
{
|
||||||
std::string_view content_type = req->getHeader("Content-Type");
|
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 accept_header = req->getHeader("Accept");
|
||||||
|
if (content_type == "applications/json")
|
||||||
{
|
{
|
||||||
fccb();
|
if (Contains(accept_header, "*/*") || Contains(accept_header, "application/json"))
|
||||||
return;
|
{
|
||||||
|
fccb();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &resp = HttpResponse::newHttpJsonResponse("Client must Accept JSON");
|
const auto &resp = HttpResponse::newHttpJsonResponse("Client must Accept JSON");
|
||||||
resp->setStatusCode(k406NotAcceptable);
|
resp->setStatusCode(k406NotAcceptable);
|
||||||
fcb(resp);
|
fcb(resp);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue