我想在API之前检查所有入口数据中的一些字符。我检入中间件,但它生成API的速度很慢。我的意思是:
1客户端发送请求=> 2 NGINX =>3 Kestrel => 4中间件=>5代码
我想在编写代码之前先检入步骤。我使用.net Core2.2
谢谢
发布于 2019-06-14 22:12:27
我想检查主体的请求,以删除额外的空格,并检查波斯字符。我对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。
我希望它能对其他人有所帮助。
https://stackoverflow.com/questions/56537255
复制相似问题