Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request help: Need to rewrite the http request method #148

Open
SherrillJoyceGit opened this issue Nov 6, 2023 · 3 comments
Open

request help: Need to rewrite the http request method #148

SherrillJoyceGit opened this issue Nov 6, 2023 · 3 comments

Comments

@SherrillJoyceGit
Copy link

SherrillJoyceGit commented Nov 6, 2023

Issue description

I need to rewrite the http request method.
I think about two ways, but both failed.
Way 1.
Add a method like "(r *Request) SetPath". As a result , I add a method to Request and call hrc.Req. MutateMethod.
It only changes the object of Request.r and does not change the buffer object(generated by flatbuffer which is a rpc solution of google). The program just use the content of buffer object to call the upstream api.

Way 2.
Based on way1 , there is no function at HTTPReqCall.Rewrite to change the method. I try to use functions of HTTPReqCall.Req to rebuild the buffer. It does't work and lua problems occurred !

Why:

We have some apis using the Get methods, and the client only use POST methods that can't be changed.
Client -> Method(POST) -> configuration in plugins -> Go Runner Plugin -> Method(GET) -> Upstream

screenshots:
image

Environment

  • APISIX Go Plugin Runner's version: v0.5.0
  • APISIX version: v3.6.0
  • Go version: 1.19.5
  • OS (cmd: uname -a): Linux localhost.localdomain 3.10.0-862.el7.x86_64 ci: enable #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
@SherrillJoyceGit SherrillJoyceGit changed the title request help: request help: Need to rewrite the http request method Nov 6, 2023
@SherrillJoyceGit
Copy link
Author

Finally,I do the request method change by writing a lua plugin.

@thinkdb1
Copy link

我最近实验修改重写body时,获得一点思路,虽然没有实验希望可以帮到你:
在apisix-core-with-plugin/internal/http/request.go中的(r *Request) FetchChanges(id uint32, builder *flatbuffers.Builder)的方法里面的hrc.RewriteStart(builder)下面,添加hrc.ReqAddMethod()这个方法,是不是可以实现重写method的方法,因为我加入hrc.RewriteAddBody这个方法后,可以重写body。当然前面要自己定义相关判断是否修改method

@TomCN0803
Copy link
Contributor

I've started a pull request: #151
Features and modifications includes:

  • Update github.com/api7/ext-plugin-proto to v0.6.1
  • Add SetBody([]byte) to http.Request
  • Add a sample request body rewrite plugin
  • Add an e2e test for the sample request body rewrite plugin
  • Lint some code and add items (e.g. .vscode, go.work) to .gitignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants