Skip to content

优化:区分 HTTP 错误,返回明确原因#752

Merged
klboke merged 3 commits intokekingcn:masterfrom
gaoxingzaq:meihua2
May 9, 2026
Merged

优化:区分 HTTP 错误,返回明确原因#752
klboke merged 3 commits intokekingcn:masterfrom
gaoxingzaq:meihua2

Conversation

@gaoxingzaq
Copy link
Copy Markdown
Contributor

1、修复 MIME 类型校验失败后仍返回成功
2、增强异常处理,区分 HTTP 客户端异常
3、完善未知异常的兜底处理

Copy link
Copy Markdown
Contributor

@klboke klboke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

发现一个需要修改的 blocker:

  • server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java:197/getCorsFile 的 HTTP 分支里用 try-with-resources 关闭了 HttpRequestUtils.createConfiguredHttpClient() 返回的 CloseableHttpClient。但这个方法返回的是 HttpRequestUtils 内部缓存的共享 client,而不是一次性 client。这样一次 /getCorsFile 请求结束后会把缓存 client 关闭,后续 PDF/image/office 等依赖 /getCorsFile 代理读取的预览请求可能复用到已关闭的 client,从而失败。建议不要在这里关闭该 client,继续让 HttpRequestUtils.shutdown() 负责缓存 client 生命周期。

验证:mvn -q -pl server -DskipTests compile 通过。

建议补一条两个连续 /getCorsFile HTTP 请求的回归测试,覆盖这个共享 client 生命周期问题。

@gaoxingzaq
Copy link
Copy Markdown
Contributor Author

已经 修复了

Copy link
Copy Markdown
Contributor

@klboke klboke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复查了最新 head,之前指出的 blocker 已修复:/getCorsFile 现在不再关闭 HttpRequestUtils.createConfiguredHttpClient() 返回的共享缓存 client,client 生命周期仍由 HttpRequestUtils.shutdown() 统一处理。

验证:mvn -q -pl server -DskipTests compile 通过。

非阻塞建议:

  • 后续可以补一条两个连续 /getCorsFile HTTP 请求的回归测试,防止共享 client 生命周期问题回归。
  • 新增的 HttpClientLifecycle 里建议用 logger 替代 System.out.println,并补文件末尾换行。

@klboke klboke merged commit 1f60e30 into kekingcn:master May 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants