This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new d5ec37eb4 chore: don't report upstream http host check error in stream 
subsystem (#6904)
d5ec37eb4 is described below

commit d5ec37eb420847242cb4b0523825eca5686d3c93
Author: 罗泽轩 <[email protected]>
AuthorDate: Sun Apr 24 10:34:01 2022 +0800

    chore: don't report upstream http host check error in stream subsystem 
(#6904)
    
    Signed-off-by: spacewander <[email protected]>
---
 apisix/upstream.lua    | 20 +++++++++++---------
 t/stream-node/sanity.t | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/apisix/upstream.lua b/apisix/upstream.lua
index 0b9ce2008..954f54aab 100644
--- a/apisix/upstream.lua
+++ b/apisix/upstream.lua
@@ -421,16 +421,18 @@ local function check_upstream_conf(in_dp, conf)
         end
     end
 
-    if conf.pass_host == "node" and conf.nodes and
-        not balancer.recreate_request and core.table.nkeys(conf.nodes) ~= 1
-    then
-        return false, "only support single node for `node` mode currently"
-    end
+    if is_http then
+        if conf.pass_host == "node" and conf.nodes and
+            not balancer.recreate_request and core.table.nkeys(conf.nodes) ~= 1
+        then
+            return false, "only support single node for `node` mode currently"
+        end
 
-    if conf.pass_host == "rewrite" and
-        (conf.upstream_host == nil or conf.upstream_host == "")
-    then
-        return false, "`upstream_host` can't be empty when `pass_host` is 
`rewrite`"
+        if conf.pass_host == "rewrite" and
+            (conf.upstream_host == nil or conf.upstream_host == "")
+        then
+            return false, "`upstream_host` can't be empty when `pass_host` is 
`rewrite`"
+        end
     end
 
     if conf.tls then
diff --git a/t/stream-node/sanity.t b/t/stream-node/sanity.t
index c1e810a18..c793f7020 100644
--- a/t/stream-node/sanity.t
+++ b/t/stream-node/sanity.t
@@ -342,3 +342,46 @@ GET /t
 --- error_code: 400
 --- response_body
 {"error_msg":"invalid remote_addr: :\/8"}
+
+
+
+=== TEST 14: skip upstream http host check in stream subsystem
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/upstreams/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "nodes": {
+                        "127.0.0.1:1995": 1,
+                        "127.0.0.2:1995": 1
+                    },
+                    "pass_host": "node",
+                    "type": "roundrobin"
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+--- skip_nginx: 5: < 1.19.0
+
+
+
+=== TEST 15: hit route
+--- stream_request eval
+mmm
+--- stream_response
+hello world
+--- no_error_log
+[error]
+--- skip_nginx: 5: < 1.19.0

Reply via email to