Commit 073ad8798ca7ddef9656eccde5852e5da5426a71
1 parent
1e762143
1446 fix: 修复API响应加密时添加加密 header 标识不生效的问题
Showing
1 changed file
with
5 additions
and
6 deletions
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/encrypt/core/filter/ApiEncryptResponseWrapper.java
| ... | ... | @@ -42,16 +42,15 @@ public class ApiEncryptResponseWrapper extends HttpServletResponseWrapper { |
| 42 | 42 | this.flushBuffer(); |
| 43 | 43 | byte[] body = byteArrayOutputStream.toByteArray(); |
| 44 | 44 | |
| 45 | - // 2. 加密 body | |
| 46 | - String encryptedBody = symmetricEncryptor != null ? symmetricEncryptor.encryptBase64(body) | |
| 47 | - : asymmetricEncryptor.encryptBase64(body, KeyType.PublicKey); | |
| 48 | - | |
| 49 | - // 3. 添加加密 header 标识(设置header要放在response的write之前) | |
| 45 | + // 2. 添加加密 header 标识 | |
| 50 | 46 | this.addHeader(properties.getHeader(), "true"); |
| 51 | 47 | // 特殊:特殊:https://juejin.cn/post/6867327674675625992 |
| 52 | 48 | this.addHeader("Access-Control-Expose-Headers", properties.getHeader()); |
| 53 | 49 | |
| 54 | - // 4. 输出加密后的 body | |
| 50 | + // 3.1 加密 body | |
| 51 | + String encryptedBody = symmetricEncryptor != null ? symmetricEncryptor.encryptBase64(body) | |
| 52 | + : asymmetricEncryptor.encryptBase64(body, KeyType.PublicKey); | |
| 53 | + // 3.2 输出加密后的 body:(设置 header 要放在 response 的 write 之前) | |
| 55 | 54 | response.getWriter().write(encryptedBody); |
| 56 | 55 | } |
| 57 | 56 | ... | ... |