spacewander commented on code in PR #7861:
URL: https://github.com/apache/apisix/pull/7861#discussion_r962508081


##########
t/plugin/proxy-mirror.t:
##########
@@ -696,3 +696,49 @@ passed
 passed
 passed
 passed
+
+
+
+=== TEST 23: set mirror requests host to domain
+--- 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://httpbin.org";,
+                               "path": "/get"
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                   }]]
+                   )
+
+               if code >= 300 then
+                   ngx.status = code
+               end
+               ngx.say(body)
+           }
+       }
+--- response_body
+passed
+
+
+
+=== TEST 24: hit route resolver domain
+--- request
+GET /hello
+--- error_code: 200

Review Comment:
   We don't need to check `error_code: 200` as it is checked by default



##########
t/plugin/proxy-mirror.t:
##########
@@ -696,3 +696,49 @@ passed
 passed
 passed
 passed
+
+
+
+=== TEST 23: set mirror requests host to domain
+--- 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://httpbin.org";,
+                               "path": "/get"
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                   }]]
+                   )
+
+               if code >= 300 then
+                   ngx.status = code
+               end
+               ngx.say(body)
+           }
+       }
+--- response_body
+passed
+
+
+
+=== TEST 24: hit route resolver domain
+--- request
+GET /hello
+--- error_code: 200
+--- response_body
+hello world
+--- error_log
+http://httpbin.org is resolved to:

Review Comment:
   Let's use a regex to validate it is indeed resolved to an IP



##########
apisix/plugins/proxy-mirror.lua:
##########
@@ -59,9 +61,22 @@ function _M.check_schema(conf)
 end
 
 
+local function resolver_host(prop_host)
+    local url_decoded = url.parse(prop_host)
+    if not core.utils.parse_ipv4(url_decoded.host) and not 
core.utils.parse_ipv6(url_decoded.host) then
+        local ip = core.resolver.parse_domain(url_decoded.host)

Review Comment:
   The parse_domain may return `err`, let's check for it



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to