背景
- 使用springmvc实现一个通用网关代理
- 使用webClient作为请求被代理服务的http客户端
- 代码大致如下:
@RequestMapping("/proxy/{path}/**")
public void execute(@PathVariable("path") String path,
HttpServletRequest request, HttpServletResponse response) throws IOException {
// 1. 准备请求, 得到webClient的WebClient.RequestBodyUriSpec proxyRequest
// 2. 处理一些业务逻辑, 确定被代理服务的请求地址
// 3. 执行请求
ResponseEntity<byte[]> proxyResponse = proxyRequest
.retrieve()
.toEntity(byte[].class)

文章讲述了在使用SpringMVC实现的网关代理中,遇到1%左右的异常,经排查发现与Transfer-Encoding:chunked的处理有关。问题源于Tomcat对HTTP协议响应头的自动维护,不能随意透传,特别是Connection和Transfer-Encoding。作者提供了问题定位和解决策略。
1万+

被折叠的 条评论
为什么被折叠?



