Search code examples
nginxasp.net-coremiddlewarekestrel-http-server

How check entrance data before web service without getting slowly?


I want to check some character in all entrance data before API. I check in middle-ware but it makes API slowly. I mean this:

1 Client send request => 2 NGINX =>3 Kestrel => 4 middle-ware=> 5 Code

I want to check in steps before code. I use .net core 2.2

thanks


Solution

  • I want to check body of request to remove extra space and check Persian character. I do this with Lua !and I say to NGINX to call it.

        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)
    

    in above I check body and replace it with proper data and again set body.

    I hope it will be help other.