monkeyDluffy6017 commented on code in PR #10425:
URL: https://github.com/apache/apisix/pull/10425#discussion_r1409012266
##########
apisix/plugins/forward-auth.lua:
##########
@@ -106,16 +106,20 @@ function _M.access(conf, ctx)
method = conf.request_method
}
+ local httpc = http.new()
if params.method == "POST" then
params.body = core.request.get_body()
+ local client_body_reader, err = httpc:get_client_body_reader()
+ if not err then
+ params.body = client_body_reader
+ end
Review Comment:
I agree with @Gallardot, it's ok to use `core.request.get_body()` if the
`content-length` is missing, the client should ensure the input format is
correct.
But we should not check the `err` value of `local client_body_reader, err =
httpc:get_client_body_reader()`, because the `err` will be `nil` if the
`content-length` is missing.
https://github.com/ledgetech/lua-resty-http/blob/master/lib/resty/http.lua#L999
So the code is like:
```
local httpc = http.new()
if params.method == "POST" then
local client_body_reader, err = httpc:get_client_body_reader()
if client_body_reader then
params.body = client_body_reader
else
params.body = core.request.get_body()
end
end
```
--
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]