如何解决Spring Cloud Open Feign:gzip响应正文中的换行符“ \ n”被剥离
在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();
}
ApplicationTest.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!
}
}
bootstrap.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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。