spring-cloud/spring-cloud-gateway

Modify Request Body for a GET request

Open

#1,147 创建于 2019年7月3日

在 GitHub 查看
 (7 评论) (0 反应) (0 负责人)Java (4,284 star) (3,204 fork)batch import
enhancementhelp wanted

描述

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?

贡献者指南