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 2022/09/05 02:30:44 UTC

[GitHub] [apisix] Strangevy opened a new pull request, #7861: feat: proxy-mirror plugin resolve host

Strangevy opened a new pull request, #7861:
URL: https://github.com/apache/apisix/pull/7861

   ### Description
   
   Fixes #7796 
   
   ### Checklist
   
   - [ ] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
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] Strangevy commented on pull request #7861: feat: proxy-mirror plugin resolve host

Posted by GitBox <gi...@apache.org>.
Strangevy commented on PR #7861:
URL: https://github.com/apache/apisix/pull/7861#issuecomment-1240284715

   > @Strangevy Please make the CI pass, thanks!
   
   Done


-- 
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] Strangevy commented on pull request #7861: feat: proxy-mirror plugin resolve host

Posted by GitBox <gi...@apache.org>.
Strangevy commented on PR #7861:
URL: https://github.com/apache/apisix/pull/7861#issuecomment-1240466779

   > @Strangevy Please make the CI pass, thanks!
   
   684970b53cc02a0fab9798d5f1c2913fb5753774 The merge commit failed the test case execution.


-- 
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 a diff in pull request #7861: feat: proxy-mirror plugin resolve host

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #7861:
URL: https://github.com/apache/apisix/pull/7861#discussion_r963276236


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

Review Comment:
   For code style, I would prefer to use `if not ip`



##########
apisix/plugins/proxy-mirror.lua:
##########
@@ -59,9 +61,30 @@ function _M.check_schema(conf)
 end
 
 
+local function resolver_host(prop_host)
+    local url_decoded = url.parse(prop_host)
+    local decoded_host = url_decoded.host
+    if not core.utils.parse_ipv4(decoded_host) and not core.utils.parse_ipv6(decoded_host) then
+        local ip, err = core.resolver.parse_domain(decoded_host)
+
+        if err then
+            core.log.error("dns resolver resolves domain: ", decoded_host, " error: ", err,
+             " will continue to use the host: ", decoded_host)

Review Comment:
   The indentation can be better



-- 
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 merged pull request #7861: feat: proxy-mirror plugin resolve host

Posted by GitBox <gi...@apache.org>.
spacewander merged PR #7861:
URL: https://github.com/apache/apisix/pull/7861


-- 
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 a diff in pull request #7861: feat: proxy-mirror plugin resolve host

Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] spacewander commented on pull request #7861: feat: proxy-mirror plugin resolve host

Posted by GitBox <gi...@apache.org>.
spacewander commented on PR #7861:
URL: https://github.com/apache/apisix/pull/7861#issuecomment-1240245170

   @Strangevy 
   Please make the CI pass, thanks!


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