spring-cloud/spring-cloud-gateway

Modify Request Body for a GET request

Open

#1147 aperta il 3 lug 2019

Vedi su GitHub
 (7 commenti) (0 reazioni) (0 assegnatari)Java (3204 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (4284 star)
Metriche merge PR
 (Merge medio 1g 21h) (18 PR mergiate in 30 g)

Descrizione

We 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?

Guida contributor