@@ -53,7 +53,7 @@ function MyPlugin:access(config)
5353 end
5454
5555 -- save vars into context for later usage
56- ngx .ctx ._parsing_error = false
56+ ngx .ctx ._parsing_error_in_access_phase = false
5757 ngx .ctx .req_uri = ngx .var .uri
5858 ngx .ctx .req_method = ngx .req .get_method ()
5959 ngx .ctx .req_json_body = _req_json_body
@@ -70,7 +70,7 @@ function MyPlugin:access(config)
7070 local l_status
7171 l_status , sandbox_f = _utils .sandbox_load (config .request_transformer , _get_env_ ())
7272 if not l_status then
73- ngx .ctx ._parsing_error = true
73+ ngx .ctx ._parsing_error_in_access_phase = true
7474 return kong .response .exit (500 , sandbox_f )
7575 end
7676 C1 :set (c1_key , sandbox_f , 300 )
@@ -79,17 +79,17 @@ function MyPlugin:access(config)
7979 local p_status , f_status , req_body_or_err = _utils .sandbox_exec (sandbox_f )
8080
8181 if not p_status then
82- ngx .ctx ._parsing_error = true
82+ ngx .ctx ._parsing_error_in_access_phase = true
8383 return kong .response .exit (500 , " transformer script parsing failure." )
8484 end
8585
8686 if not f_status then
87- ngx .ctx ._parsing_error = true
87+ ngx .ctx ._parsing_error_in_access_phase = true
8888 return kong .response .exit (500 , req_body_or_err )
8989 end
9090
9191 if type (req_body_or_err ) ~= " string" then
92- ngx .ctx ._parsing_error = true
92+ ngx .ctx ._parsing_error_in_access_phase = true
9393 return kong .response .exit (500 , " unknown error" )
9494 end
9595
@@ -103,11 +103,11 @@ end
103103
104104
105105function MyPlugin :header_filter (config )
106- ngx .header [" content-length" ] = nil -- this needs to be for the content-length to be recalculated
107-
108- if ngx .ctx ._parsing_error then
106+ MyPlugin .super .header_filter (self )
107+ if ngx .ctx ._parsing_error_in_access_phase then
109108 return
110109 end
110+ ngx .header [" content-length" ] = nil -- this needs to be for the content-length to be recalculated
111111 if config .http_200_always then
112112 ngx .status = 200
113113 end
116116
117117function MyPlugin :body_filter (config )
118118 MyPlugin .super .body_filter (self )
119+ if ngx .ctx ._parsing_error_in_access_phase then
120+ return
121+ end
119122
120123 local chunk , eof = ngx .arg [1 ], ngx .arg [2 ]
121124
@@ -141,7 +144,7 @@ function MyPlugin:body_filter(config)
141144 local l_status
142145 l_status , sandbox_f = _utils .sandbox_load (config .response_transformer , _get_env_ ())
143146 if not l_status then
144- ngx .ctx ._parsing_error = true
147+ ngx .ctx ._parsing_error_in_access_phase = true
145148 return kong .response .exit (500 , sandbox_f )
146149 end
147150 C1 :set (c1_key , sandbox_f , 300 )
0 commit comments