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 2023/01/03 05:47:46 UTC
[GitHub] [apisix] spacewander commented on a diff in pull request #8587: fix: issue 8511 The format of response body that returned by plugin should match Content-Type
spacewander commented on code in PR #8587:
URL: https://github.com/apache/apisix/pull/8587#discussion_r1060291836
##########
apisix/core/response.lua:
##########
@@ -80,7 +115,20 @@ function resp_exit(code, ...)
end
if idx > 0 then
- ngx_print(concat_tab(t, "", 1, idx))
+ local response = concat_tab(t, "", 1, idx)
+ local _, err = decode_json(response)
+ if not err then
+ local content_type = ngx_header["Content-type"]
+ local accept_header = ngx.req.get_headers()["Accept"]
Review Comment:
We can use https://github.com/apache/apisix/blob/c0c906eb4d62886ffa4b0938b017dc4810cfe639/apisix/core/request.lua#L104 which gets the header from cache
##########
apisix/core/response.lua:
##########
@@ -80,7 +115,20 @@ function resp_exit(code, ...)
end
if idx > 0 then
- ngx_print(concat_tab(t, "", 1, idx))
+ local response = concat_tab(t, "", 1, idx)
+ local _, err = decode_json(response)
Review Comment:
It would be more effective to check the header first before decoding, so we can save lots of unnecessary decoding.
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org