禁用 transfer-encoding:在 Spring Webflux 响应中分块

Disable transfer-encoding: chunked in Spring Webflux responses

我使用 Spring Webflux 反应库创建了一堆 REST API 端点。我现在面临的问题是 spring Webflux returns 的响应有 transfer-encoding: chunked HTTP header。由于使用像 Axios (https://github.com/axios/axios) 这样的库的客户端应用程序来自浏览器 javascript 的基于承诺的 HTTP 客户端失败。我们如何关闭 transfer-encoding: chunked ?

使用 curl 来自 Spring webflux 应用程序的示例响应:

< HTTP/1.1 200 OK
< transfer-encoding: chunked
< Content-Type: application/json;charset=UTF-8
<
[{"default_project_id":"admin","description" .......
"name":**"use* Connection #0 to host 10.1.0.9 left intact**
r1"}},"links":{"self":"http://10.10.10.51:5000/v3/users/f6ee9d6217404d2ba73f323edff06bf8"},
"password_expires_at":null,
"id":"f6ee9d6217404d2ba73f323edff06bf8"}]

请帮忙。我看到了整个响应,但响应的分块正在丢弃 http 客户端库,尤其是从 Web 浏览器中使用它们。

我认为您无法使用 Reactor Netty(Spring Boot + WebFlux 使用的默认服务器)禁用分块编码。另一种方法是设置 Content-Length header,这意味着在将整个响应写入网络之前对其进行缓冲。这对于背压支持来说并不是最佳选择。

我查了axios客户端,只找到一个opened issue about HTTP streaming support,和Transfer-Encoding: chunked不一样。您能否详细说明您是如何得出该结论的?