Modify Request Body for a GET request
See original GitHub issueWe currently have custom code for modifying request body which works but I want to move to the standard ModifyRequestBodyGatewayFilterFactory
.
We have a scenario where Spring Cloud Gateway received a GET request and we need call an internal GraphQL api with a POST and a request body.
ModifyRequestBodyGatewayFilterFactory
works great if there is a body present in the original request but doesn’t apply the rewriteFunction
when there is no body on GET requests.
I am using v2.1.2.RELEASE and I have hacked together a change to ModifyRequestBodyGatewayFilterFactory
which works for me:
Mono<?> modifiedBody = serverRequest.bodyToMono(inClass)
.defaultIfEmpty("") //added this line
.flatMap(o -> config.rewriteFunction.apply(exchange, o));
I appreciate that the ModifyRequestBodyGatewayFilterFactory
is beta, but would it be possible to support adding a body for GET requests in the future?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to modify request body - node.js - Stack Overflow
This should help you get started: addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) async function ...
Read more >Modifying the Request Body - TIBCO Product Documentation
To modify the request body in the pre-processing stage employ the content source ... Get Content source from request. Get input stream from...
Read more >How to change request body before sending request - Help
I need to change the request body data before sending to server. I'm loading data from a json file. Json file may have...
Read more >Add a Request Body to a POST Request | API Connector
Enter a Request Body ... As part of a POST, PUT, or PATCH request, a data payload can be sent to the server...
Read more >Issues - GitHub
how to modify request.body/form/query in middleware? ... request.state like request.state.username=username ? if ok , then how to get in ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not sure I like the edit.
I think I prefer this (closer to what was there prior to the edit).
I don’t like the idea of having a body with an empty string. I also think it might need to be opt-in since it is very unusual.
I’m not sure this exactly covers the use-case of this issue, but I worked around empty body in usage of
modifyRequestBody
by testing for null the original body and returning Mono.empty() when null body.and submitted https://github.com/spring-cloud/spring-cloud-gateway/pull/2000