File tree Expand file tree Collapse file tree 2 files changed +107
-1
lines changed Expand file tree Collapse file tree 2 files changed +107
-1
lines changed Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ local function get_full_log(ngx, conf)
198198 apisix_latency = apisix_latency
199199 }
200200
201- if ctx . resp_body then
201+ if conf . include_resp_body then
202202 log .response .body = ctx .resp_body
203203 end
204204
Original file line number Diff line number Diff line change @@ -715,3 +715,109 @@ passed
715715--- request
716716GET /hello1
717717--- wait: 3
718+
719+
720+
721+ === TEST 24: set route with include_resp_body enabled
722+ --- config
723+ location /t {
724+ content_by_lua_block {
725+ local t = require("lib.test_admin").test
726+ local code, body = t('/apisix/admin/routes/1',
727+ ngx.HTTP_PUT,
728+ [[{
729+ "plugins": {
730+ "http-logger": {
731+ "uri": "http://127.0.0.1:1982/log",
732+ "batch_max_size": 1,
733+ "max_retry_count": 1,
734+ "retry_delay": 2,
735+ "buffer_duration": 2,
736+ "inactive_timeout": 2,
737+ "include_resp_body": true
738+ }
739+ },
740+ "upstream": {
741+ "nodes": {
742+ "127.0.0.1:1982": 1
743+ },
744+ "type": "roundrobin"
745+ },
746+ "uri": "/hello"
747+ }]]
748+ )
749+
750+ if code >= 300 then
751+ ngx.status = code
752+ end
753+ ngx.say(body)
754+ }
755+ }
756+ --- response_body
757+ passed
758+
759+
760+
761+ === TEST 25: test http logger with include_resp_body
762+ --- request
763+ GET /hello
764+ --- response_body
765+ hello world
766+ --- error_log eval
767+ qr/request log:.*"response":\{"body":"hello world\\n"/
768+ --- wait: 1.5
769+
770+
771+
772+ === TEST 26: set route with http-logger include_resp_body disabled file-logger include_resp_body enabled
773+ --- config
774+ location /t {
775+ content_by_lua_block {
776+ local t = require("lib.test_admin").test
777+ local code, body = t('/apisix/admin/routes/1',
778+ ngx.HTTP_PUT,
779+ [[{
780+ "plugins": {
781+ "http-logger": {
782+ "uri": "http://127.0.0.1:1982/log",
783+ "batch_max_size": 1,
784+ "max_retry_count": 1,
785+ "retry_delay": 2,
786+ "buffer_duration": 2,
787+ "inactive_timeout": 2,
788+ "include_resp_body": false
789+ },
790+ "file-logger": {
791+ "path": "/var/log/apisix/file.log",
792+ "include_resp_body": true
793+ }
794+ },
795+ "upstream": {
796+ "nodes": {
797+ "127.0.0.1:1982": 1
798+ },
799+ "type": "roundrobin"
800+ },
801+ "uri": "/hello"
802+ }]]
803+ )
804+
805+ if code >= 300 then
806+ ngx.status = code
807+ end
808+ ngx.say(body)
809+ }
810+ }
811+ --- response_body
812+ passed
813+
814+
815+
816+ === TEST 27: test http logger without log response body
817+ --- request
818+ GET /hello
819+ --- response_body
820+ hello world
821+ --- error_log eval
822+ qr/request log:(?!.*"body")/
823+ --- wait: 1.5
You can’t perform that action at this time.
0 commit comments