如何在不慢的情况下检查web服务前的入口数据?

How check entrance data before web service without getting slowly?

我想检查API之前所有入口数据中的一些字符。 我检查了中间件,但它使 API 变慢了。 我的意思是:

1 客户端发送请求=> 2 NGINX =>3 Kestrel => 4 中间件=> 5 代码

我想在代码之前检查步骤。我使用.net core 2.2

谢谢

我想检查请求正文以删除多余的 space 并检查波斯字符。 我使用 Lua 执行此操作!我告诉 NGINX 调用它。

    local string_format = string.format
    ngx.req.read_body()
    local body = ngx.req.get_body_data() or ""
   -- Replace 'Ye' and 'Kaf' arabic char with persian
   body = ngx.re.gsub(body, "ي", "ی") -- remove id and name
   body = ngx.re.gsub(body, "ك", "ک") -- remove id and name
   -- Remove useless space
   body = ngx.re.gsub(body, "  ", " ") -- remove id and name
   body = ngx.re.gsub(body, '" ', '"') -- remove id and name
   body = ngx.re.gsub(body, ' "', '"') -- remove id and name
   ngx.req.set_body_data(body)

在上面,我检查了 body 并将其替换为正确的数据,然后再次设置 body。

希望对其他人有所帮助