在 Spring Cloud Open Feign 中使用响应压缩配置(如下所示)时,从gzip响应正文中删除了换行符(“\n”或“\r”)。没有引发错误。换行符只是被空字符串“”替换。响应具有正确的“content-encoding: gzip”标头和格式良好的 gzip 压缩正文内容。
有人有线索吗?当我在这里打开spring-cloud-openfeign/issue400 时,这对我来说似乎是个问题
feign.compression.response.enabled: true
feign.compression.response.useGzipDecoder: true
# Same behaviour using Apache Http as client
feign.httpclient.enabled: true
SpringCloudFeignClient.java
package springcloudfeigngzip;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
@FeignClient(name = "SpringCloudFeignClient", url = "http://localhost:8082")
public interface SpringCloudFeignClient {
@GetMapping(value = "/gzip")
String getGzippedString();
}
应用程序测试.java:
package springcloudfeigngzip;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
@AutoConfigureWireMock(port = 8082)
class ApplicationTest {
@Autowired
private SpringCloudFeignClient springCloudFeignClient;
@Test
void success_GzipOneLine() {
stubFor(get(urlEqualTo("/gzip")).withHeader("Accept-Encoding", containing("gzip"))
.willReturn(aResponse().withStatus(200).withBody("lineone")));
String response = springCloudFeignClient.getGzippedString();
assertEquals("lineone", response); //success
}
@Test
void fail_GzipLineBreak() {
stubFor(get(urlEqualTo("/gzip")).withHeader("Accept-Encoding", containing("gzip"))
.willReturn(aResponse().withStatus(200).withBody("lineone\nlinetwo")));
String response = springCloudFeignClient.getGzippedString();
assertEquals("lineone\nlinetwo", response); //fail!
}
}
引导程序.yml:
feign:
compression:
response:
enabled: true
useGzipDecoder: true
版本:
org.springframework.boot: 2.3.3.RELEASE
org.springframework.cloud: Hoxton.SR8
完整项目在这里: https ://github.com/spring-cloud/spring-cloud-openfeign/files/5147346/spring-cloud-feign-gzip.zip