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/06/09 01:03:36 UTC

[GitHub] [apisix] tokers commented on a change in pull request #4391: feat(mqtt-proxy): support domain

tokers commented on a change in pull request #4391:
URL: https://github.com/apache/apisix/pull/4391#discussion_r647892650



##########
File path: apisix/stream/plugins/mqtt-proxy.lua
##########
@@ -159,16 +165,38 @@ function _M.preread(conf, ctx)
 
     core.log.info("mqtt client id: ", res.client_id)
 
+    local host = conf.upstream.host
+    if not host then
+        host = conf.upstream.ip
+    end
+
+    if conf.host_is_domain == nil then
+        conf.host_is_domain = not ipmatcher.parse_ipv4(host)
+                              and not ipmatcher.parse_ipv6(host)
+    end
+
+    if conf.host_is_domain then
+        local ip, err = core.resolver.parse_domain(host)
+        if not ip then
+            core.log.error("failed to parse host ", host, ", err: ", err)
+            return 500

Review comment:
       Other places in this method just call `ngx.exit(1)`, why here we need to return `500`.

##########
File path: apisix/stream/plugins/mqtt-proxy.lua
##########
@@ -159,16 +165,38 @@ function _M.preread(conf, ctx)
 
     core.log.info("mqtt client id: ", res.client_id)
 
+    local host = conf.upstream.host
+    if not host then
+        host = conf.upstream.ip
+    end
+
+    if conf.host_is_domain == nil then
+        conf.host_is_domain = not ipmatcher.parse_ipv4(host)
+                              and not ipmatcher.parse_ipv6(host)
+    end
+
+    if conf.host_is_domain then
+        local ip, err = core.resolver.parse_domain(host)
+        if not ip then
+            core.log.error("failed to parse host ", host, ", err: ", err)
+            return 500
+        end
+
+        host = ip
+    end
+
     local up_conf = {
         type = "roundrobin",
         nodes = {
-            {host = conf.upstream.ip, port = conf.upstream.port, weight = 1},
+            {host = host, port = conf.upstream.port, weight = 1},
         }
     }
 
     local ok, err = upstream.check_schema(up_conf)
     if not ok then
-        return 500, err
+        core.log.error("failed to check schema ", core.json.delay_encode(up_conf),
+                       ", err: ", err)
+        return 500

Review comment:
       Ditto.




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