spring-cloud/spring-cloud-gateway

Modify Request Body for a GET request

Open

#1,147 opened on 2019年7月3日

GitHub で見る
 (7 comments) (0 reactions) (0 assignees)Java (3,204 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (4,284 stars)
PR merge metrics
 (平均マージ 1d 21h) (30d で 18 merged PRs)

説明

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?

コントリビューターガイド