Open yyl-code opened 1 year ago
Not yet supported
........
i want change request body
我试着修改了几个文件,发现可以修改request body值了,先发你先参考看看
apisix-core-with-plugin/internal/http/request.go中 1.加入
func (r *Request) SetBody(b []byte) {
r.body = b
}
2.在(r Request) FetchChanges(id uint32, builder flatbuffers.Builder)中把
if r.path == nil && r.hdr == nil && r.args == nil && r.respHdr == nil {
return false
}
改为
if r.path == nil && r.hdr == nil && r.args == nil && r.respHdr == nil && r.body == nil {
return false
}
3.在(r Request) FetchChanges(id uint32, builder flatbuffers.Builder)中在
if r.path != nil {
path = builder.CreateByteString(r.path)
}
后加入
if r.body != nil {
body = builder.CreateByteString(r.body)
}
4.在(r Request) FetchChanges(id uint32, builder flatbuffers.Builder)中把
var path flatbuffers.UOffsetT
改为
var path, body flatbuffers.UOffsetT
5.在(r Request) FetchChanges(id uint32, builder flatbuffers.Builder)中在
if path > 0 {
hrc.RewriteAddPath(builder, path)
}
后加入
if body > 0 {
hrc.RewriteAddBody(builder, body)
}
6.在apisix-core-with-plugin/pkg/http/http.go中的Request interface加入 SetBody([]byte) 7.在go.mod中github.com/api7/ext-plugin-proto改为v0.6.1
在使用时使用r.SetBody([]byte("mytestbody"))并且在apisix的3.6.0版本下使用就可以了,我只是试用成功了,没测试是否还有其他问题
I've started a pull request: #151 Features and modifications includes:
the setBody([]byte) works fine when using only "ext-plugin-pre-req" once using both "ext-plugin-pre-req" and "ext-plugin-post-resp", it doesn't work.
Issue description
Does the golang plugin support modifying the request body?
Environment
uname -a
):