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 2020/11/03 14:45:39 UTC

[GitHub] [apisix] Firstsawyou opened a new issue #2617: request help: after proxy-mirror plugin mirroring request, the host in the mirroring request has changed

Firstsawyou opened a new issue #2617:
URL: https://github.com/apache/apisix/issues/2617


   ### Issue description
   
   When I only used the `proxy-mirror` plugin, I found that the `host` in the mirroring request was not the host in the original request, but the host configured in the `proxy-mirror` plugin.
   
   This is my test case in `proxy-mirror.t` :
   
   1.Add 1986 port service, used to print mirroring request information in the log.
   
   ```
   add_block_preprocessor(sub {
       my ($block) = @_;
   
       my $http_config = $block->http_config // <<_EOC_;
   
       server {
           listen 1986;
           server_tokens off;
   
           location / {
               content_by_lua_block {
                   local core = require("apisix.core")
                   local headers_tab = ngx.req.get_headers()                
                   core.log.warn(ngx.var.request)
                   for k, v in pairs(headers_tab) do                    
                       core.log.warn( "k: ", k, " v: ", v)
                   end                
               }
           }
       }
   _EOC_
   
       $block->set_value("http_config", $http_config);
   });
   ```
   
   2.Configure `proxy-mirror` plugin information
   
   ```
   === TEST 1: sanity check (normal case)
   --- config
          location /t {
              content_by_lua_block {
                  local t = require("lib.test_admin").test
                  local code, body = t('/apisix/admin/routes/1',
                       ngx.HTTP_PUT,
                       [[{
                           "plugins": {
                               "proxy-mirror": {
                                  "host": "http://127.0.0.1:1986"
                               }
                           },
                           "upstream": {
                               "nodes": {
                                   "127.0.0.1:1980": 1
                               },
                               "type": "roundrobin"
                           },
                           "uri": "/uri"
                      }]]
                      )
   
                  if code >= 300 then
                      ngx.status = code
                  end
                  ngx.say(body)
              }
           }
   --- request
   GET /t
   --- error_code: 200
   --- response_body
   passed
   --- no_error_log
   [error]
   ```
   
   3.Send a request to test the plugin.
   
   ```
   === TEST 9: 
   --- request
   GET /uri
   --- error_code: 200
   --- more_headers
   host: 127.0.0.1
   api-key: hello
   pageSize: 11
   name: jake
   --- response_body
   uri: /uri
   host: 127.0.0.1
   pagesize: 11
   x-real-ip: 127.0.0.1
   name: jake
   api-key: hello
   --- no_error_log
   [error]
   ```
   
   4.View the printed log, host is the host configured in the proxy-mirror plugin :
   
   ![image](https://user-images.githubusercontent.com/52862365/97999150-eafcee80-1e25-11eb-8414-0b93f8ba4865.png)
   
   
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] spacewander closed issue #2617: bug(proxy-mirror): after proxy-mirror plugin mirroring request, the host in the mirroring request has changed

Posted by GitBox <gi...@apache.org>.
spacewander closed issue #2617:
URL: https://github.com/apache/apisix/issues/2617


   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2617: request help: after proxy-mirror plugin mirroring request, the host in the mirroring request has changed

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


   I got it. That is a bug:
   
   https://github.com/apache/apisix/blob/master/apisix/cli/ngx_tpl.lua#L501
   
   we need to set the correct host in this way:
   
   https://github.com/apache/apisix/blob/master/apisix/cli/ngx_tpl.lua#L392
   
   welcome PR


----------------------------------------------------------------
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.

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



[GitHub] [apisix] Firstsawyou commented on issue #2617: bug(proxy-mirror): after proxy-mirror plugin mirroring request, the host in the mirroring request has changed

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


   Assigned to me.


----------------------------------------------------------------
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.

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