soulbird commented on code in PR #7947:
URL: https://github.com/apache/apisix/pull/7947#discussion_r975921673


##########
t/plugin/ext-plugin/extra-info.t:
##########
@@ -181,3 +182,161 @@ GET /hello
 --- error_code: 503
 --- error_log
 failed to receive RPC_HTTP_REQ_CALL: closed
+
+
+
+=== TEST 5: ask response body (not exist)
+--- request
+GET /hello
+--- extra_stream_config
+    server {
+        listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
+
+        content_by_lua_block {
+            local ext = require("lib.ext-plugin")
+            local actions = {
+                {type = "respbody", result = nil}
+            }
+            ext.go({extra_info = actions})
+        }
+    }
+--- error_code: 200
+--- error_log: failed to read response body: not exits
+
+
+
+=== TEST 6: add route with ext-plugin-post-resp
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin")
+
+            local code, message, res = t.test('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                 [[{
+                    "uri": "/*",
+                    "plugins": {
+                        "ext-plugin-post-resp": {
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    }
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(message)
+                return
+            end
+
+            ngx.say(message)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 7: ask var
+--- request
+GET /hello?x=
+--- extra_stream_config
+    server {
+        listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
+
+        content_by_lua_block {
+            local ext = require("lib.ext-plugin")
+            local actions = {
+                {type = "var", name = "server_addr", result = "127.0.0.1"},
+                {type = "var", name = "remote_addr", result = "127.0.0.1"},
+                {type = "var", name = "route_id", result = "1"},
+                {type = "var", name = "arg_x", result = ""},
+            }
+            ext.go({extra_info = actions})
+        }
+    }
+--- error_code: 200
+--- grep_error_log eval
+qr/send extra info req successfully/
+--- grep_error_log_out
+send extra info req successfully
+send extra info req successfully
+send extra info req successfully
+send extra info req successfully
+--- response_body
+hello world
+
+
+
+=== TEST 8: ask response body
+--- request
+GET /hello
+--- extra_stream_config
+    server {
+        listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
+
+        content_by_lua_block {
+            local ext = require("lib.ext-plugin")
+            local actions = {
+                {type = "respbody", result = "hello world\n"},
+            }
+            ext.go({extra_info = actions})
+        }
+    }
+--- error_code: 200
+--- grep_error_log eval
+qr/send extra info req successfully/
+--- grep_error_log_out
+send extra info req successfully
+--- response_body
+hello world
+
+
+
+=== TEST 9: ask response body (chunked)
+--- request
+GET /hello_chunked
+--- extra_stream_config
+    server {
+        listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
+
+        content_by_lua_block {
+            local ext = require("lib.ext-plugin")
+            local actions = {
+                {type = "respbody", result = "hello world\n"},
+            }
+            ext.go({extra_info = actions})
+        }
+    }
+--- error_code: 200
+--- grep_error_log eval
+qr/send extra info req successfully/
+--- grep_error_log_out
+send extra info req successfully
+--- response_body
+hello world
+
+
+
+=== TEST 10: ask request body (not exist)

Review Comment:
   I reused the 
[handle_extra_info](https://github.com/apache/apisix/blob/master/apisix/plugins/ext-plugin/init.lua#L283)
 function to get the response body, the request body is part of this function.



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