apache / apisix-go-plugin-runner

Go Plugin Runner for APISIX
https://apisix.apache.org/
Apache License 2.0
169 stars 69 forks source link

request help: pkgHttp.Request can't handle body data? #52

Closed hwyzleo closed 2 years ago

hwyzleo commented 2 years ago

Issue description

I found that pkgHttp.Request does not support getting request body. I tried to use hrc.GetRootAsStop(buf, 0).BodyBytes() to get the body data, but I got the following error:

ERROR   server/server.go:69     panic recovered: runtime error: slice bounds out of range [5153:864]
github.com/apache/apisix-go-plugin-runner/internal/server.recoverPanic
apisix-go-plugin-runner/internal/server/server.go:69
github.com/google/flatbuffers/go.(*Table).ByteVector
github.com/google/flatbuffers@v2.0.0+incompatible/go/table.go:37
ext-plugin-proto/go/A6/HTTPReqCall.(*Stop).BodyBytes
github.com/api7/ext-plugin-proto@v0.3.0/go/A6/HTTPReqCall/Stop.go:90
github.com/apache/apisix-go-plugin-runner/internal/http.CreateRequest
apisix-go-plugin-runner/internal/http/request.go:351

will this function be added in the later version?

Environment

spacewander commented 2 years ago

The feature is not supported yet, but is already in our plan.

GhangZh commented 2 years ago

The feature is not supported yet, but is already in our plan.

When is this expected to be supported?

spacewander commented 2 years ago

@GhangZh Will you give it a try? I can provide some assistance.

fifsky commented 2 years ago

I also really need this functionality. My case is to validate the signature of the API request, and without the Request Body, the signature value cannot be validate

hwyzleo commented 2 years ago

@GhangZh Will you give it a try? I can provide some assistance.

I'd like to try it out, but documentation for ext-plugin-proto HTTPReqCall seems pretty sparse, any documentation or best practices can be provide?

spacewander commented 2 years ago

You can take a look at https://github.com/apache/apisix-go-plugin-runner/commit/6d1933ab4835bfbec2a02cc035660b5496df414f.

We can ask for a request body via https://github.com/api7/ext-plugin-proto/blob/70ee1218b214fd206a8a949fb0f4f7d00f9e460f/ext-plugin.fbs#L130 field.

Note that the request body feature in APISIX is only in the master branch: https://github.com/apache/apisix/commit/e7ceda0387909ba41c0eb90a897c7b70e1e96545#diff-2e15ac3df139146937e760c07adfcd597402a4abfcf512384003166b6d765009 So you need to develop this feature with the APISIX in the master branch.

spacewander commented 2 years ago

Already done.