You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/08/26 12:22:03 UTC

[GitHub] [apisix] zuiyangqingzhou opened a new issue #4905: request help: the problem with the response-rewrite plugin

zuiyangqingzhou opened a new issue #4905:
URL: https://github.com/apache/apisix/issues/4905


   ### Issue description
   
   As we all know, due to openResty, body_filter_by_lua* may be called multiple times in a single request, but response-rewrite plugin will Interrupt request on the body_filter_by_lua*  first by called, The subsequent process will not be requested.  the code is as follows
   
   https://github.com/apache/apisix/blob/master/apisix/plugins/response-rewrite.lua#L137
   
    I think it will be better to merge the result of calling body_filter_by_lua* for many times and finally replace it with the configured body, what do you think? @spacewander 
   
   ### Environment
   
   - apisix version (cmd: `apisix version`):
   - OS (cmd: `uname -a`):
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   - apisix-dashboard version, if have:
   - luarocks version, if the issue is about installation (cmd: `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906880695


   I am quite confused. Let me repeat my word for you:
   
   > It will skip content_by_lua_block even not body_filter_by_lua involve.
   
   Why do you want to change body_filter_by_lua when it is not involved?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] zuiyangqingzhou commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zuiyangqingzhou commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906889992


   You may have misunderstood me, I was referring to optimizations of response-rewrite plugin, because response-rewrite plugin run at the body_filter_by_lua phase and has the above test code.
   
   I hope that response in the access_by_lua phase and response in the content_by_lua phase can be combined, and finally replaced in body_filter_by_lua phase.
   
   It's just a little personal advice


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] zuiyangqingzhou commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zuiyangqingzhou commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906891902


   > Since we just replace it with a constant body, we don't need to wait for the upstream response.
   
   But for some special scenarios, we need to wait for the upstream response, for example, we need related request log


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906844669


   Could you provide a real example to show us if this is wrong?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906526491


   perhaps we could cache the flag of the first call to `body_filter` and just skip it if it has been called, just an idea, not practiced.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] zuiyangqingzhou commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zuiyangqingzhou commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906894149


   > > Since we just replace it with a constant body, we don't need to wait for the upstream response.
   > 
   > But for some special scenarios, we need to wait for the upstream response, for example, we need related request log
   
   In addition, is it possible to consider regular replacement by specifying some keywords in response instead of directly replacing the whole response


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906843287


   Since we just replace it with a constant body, we don't need to wait for the upstream response.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906870172


   I see. It is not relative to the body_filter_by_lua. When the output is generated in the previous phase, the content phase will be skipped.
   
   Here is a case:
   ```
       server {
           server_name 127.0.0.1; #
           listen 6688;
   
           location / {
               access_by_lua_block {
                   ngx.log(ngx.ERR, "run access block")
                   ngx.say("AAA")
               }
               content_by_lua_block {
                   ngx.log(ngx.ERR, "run content block")
                   ngx.say("BBB")
               }
           }
       }
   ```
   
   It will skip content_by_lua_block even not body_filter_by_lua involve.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] zuiyangqingzhou commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zuiyangqingzhou commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906875075


   got it, but I think it would be better to change the code below like this
   ```
   server {
           server_name 127.0.0.1; #
           listen 6688;
   
           location / {
               access_by_lua_block {
                   ngx.log(ngx.ERR, "run access block")
                   ngx.say("AAA")
               }
               content_by_lua_block {
                   ngx.log(ngx.ERR, "run content block")
                   ngx.say("BBB")
               }
               body_filter_by_lua_block {
                   ngx.log(ngx.ERR, "run body filter")
                   local chunk, eof = ngx.arg[1], ngx.arg[2]
                   # todo merge response
                   if eof then
                       ngx.arg[1] = "CCC"
                       ngx.arg[2] = true
                   end
               }
           }
       }
   ```
   what do you think? @spacewander 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] zuiyangqingzhou commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
zuiyangqingzhou commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906868206


   Here's my test code
   ```
   server {
           server_name 127.0.0.1; #
           listen 6688;
   
           location / {
               access_by_lua_block {
                   ngx.log(ngx.ERR, "run access block")
                   ngx.say("AAA")
               }
               content_by_lua_block {
                   ngx.log(ngx.ERR, "run content block")
                   ngx.say("BBB")
               }
               body_filter_by_lua_block {
                   ngx.log(ngx.ERR, "run body filter")
                   ngx.arg[1] = "CCC"
                   ngx.arg[2] = true
               }
           }
       }
   ```
   
   Here is my test log
   ```
   2021/08/27 09:57:28 [error] 44873#22580957: *1 [lua] access_by_lua(nginx.conf:75):2: run access block, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", host: "127.0.0.1:6688"
   2021/08/27 09:57:28 [error] 44873#22580957: *1 [lua] body_filter_by_lua:2: run body filter, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", host: "127.0.0.1:6688"
   ```
   
   You can see that only access_by_lua_block are called and content_by_lua_block not, I mean that the phase before the body_filter_by_lua_block should be called   @spacewander 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-908027230


   if you modify the response body in `body_filter_by_lua`, it means that you don't care what the upstream return, so why we need to wait for the upstream response? Can you give a convincing scenario?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4905: request help: the problem with the response-rewrite plugin

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4905:
URL: https://github.com/apache/apisix/issues/4905#issuecomment-906857013


   > but response-rewrite plugin will Interrupt request on the body_filter_by_lua* first by called, The subsequent process will not be requested
   
   I just spend some time making an example:
   ```
       server {
           listen 127.0.0.1:2980;
   
           location / {
               content_by_lua_block {
                   ngx.say("AAA")
                   ngx.flush(true)
                   for i = 1, 3 do
                       ngx.sleep(1)
                       ngx.log(ngx.ERR, "I am still running")
                       ngx.say("AAA")
                       ngx.flush(true)
                   end
               }
               header_filter_by_lua_block {
                   ngx.header.content_length = nil
               }
               body_filter_by_lua_block {
                   ngx.log(ngx.ERR, "run body filter")
                   ngx.arg[1] = "BBB"
                   ngx.arg[2] = true
               }
           }
   ```
   
   
   The request will keep processing (logging "I am still running") even the output is already handled by the body_filter.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org