Copilot commented on code in PR #8035:
URL: https://github.com/apache/incubator-seata/pull/8035#discussion_r3014210960
##########
namingserver/src/main/java/org/apache/seata/namingserver/filter/ConsoleRemotingFilter.java:
##########
@@ -108,33 +108,48 @@ public void doFilter(ServletRequest servletRequest,
ServletResponse servletRespo
.forEach(headerName ->
headers.add(headerName, request.getHeader(headerName)));
// Create the HttpEntity with headers and body
- HttpEntity<byte[]> httpEntity = new
HttpEntity<>(request.getCachedBody(), headers);
HttpMethod httpMethod;
try {
httpMethod =
HttpMethod.valueOf(request.getMethod());
} catch (IllegalArgumentException ex) {
- logger.error("Unsupported HTTP method: {}",
request.getMethod(), ex);
+ LOGGER.error("Unsupported HTTP method: {}",
request.getMethod(), ex);
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
+
+ // GET/HEAD methods should not have a body; other
methods may include a body as needed.
+ HttpEntity<byte[]> httpEntity;
+ if (HttpMethod.GET.equals(httpMethod) ||
HttpMethod.HEAD.equals(httpMethod)) {
+ headers.remove(HttpHeaders.CONTENT_LENGTH);
+ headers.remove(HttpHeaders.TRANSFER_ENCODING);
+ httpEntity = new HttpEntity<>(headers); //
headers-only
+ } else {
+ byte[] body = request.getCachedBody();
+ httpEntity = (body == null || body.length == 0)
+ ? new HttpEntity<>(new byte[0],
headers)
+ : new HttpEntity<>(body, headers);
+ }
+
try {
- ResponseEntity<byte[]> responseEntity =
restTemplate.exchange(
- URI.create(targetUrl), httpMethod,
httpEntity, byte[].class);
+ ResponseEntity<byte[]> responseEntity =
restTemplate.exchange(URI.create(targetUrl), httpMethod, httpEntity,
byte[].class);
responseEntity.getHeaders().forEach((key,
value) -> {
value.forEach(v -> response.addHeader(key,
v));
});
- response.setStatus(
-
responseEntity.getStatusCode().value());
+ if (response.getContentType() == null) {
+
response.setContentType("application/json;charset=UTF-8");
Review Comment:
`responseEntity.getHeaders()` are copied via `response.addHeader(...)`, but
`response.getContentType()` may still be `null` in common servlet containers
when `Content-Type` is added this way. This can cause the code to always
override the proxied `Content-Type` (e.g., JS/CSS/HTML under
`/api/**/console/**`) with `application/json;charset=UTF-8`. Consider deriving
the content type from
`responseEntity.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE)` /
`getContentType()` and calling `response.setContentType(...)` only when the
upstream didn’t provide one (or avoid setting a default here entirely).
```suggestion
String proxiedContentType =
responseEntity.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
if (response.getContentType() == null) {
if (proxiedContentType != null) {
response.setContentType(proxiedContentType);
} else {
response.setContentType("application/json;charset=UTF-8");
}
```
##########
changes/zh-cn/2.x.md:
##########
@@ -36,6 +36,7 @@
- [[#7956](https://github.com/apache/incubator-seata/pull/7956)]
修复本地JDK17以上jacoco报告为空的问题
- [[#7965](https://github.com/apache/incubator-seata/pull/7965)] 修复在 dm 和
kingbase 中当没有将索引设置为主键索引时出现的问题
- [[#7992](https://github.com/apache/incubator-seata/pull/7992)]
修复报告分支事务状态时没有设置分支类型
+- [[#8035](https://github.com/apache/incubator-seata/pull/8035)]
修复GET请求有请求体的时候出现 illegalArgumentException
Review Comment:
变更记录里写的是 `illegalArgumentException`,建议改为 Java 异常类的标准写法
`IllegalArgumentException`(首字母大写),保持一致性。
```suggestion
- [[#8035](https://github.com/apache/incubator-seata/pull/8035)]
修复GET请求有请求体的时候出现 IllegalArgumentException
```
##########
changes/en-us/2.x.md:
##########
@@ -35,6 +35,9 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7956](https://github.com/apache/incubator-seata/pull/7956)] fix empty
jacoco report on local when jdk above 17
- [[#7965](https://github.com/apache/incubator-seata/pull/7965)] fix the issue
where different element order in two lists causes failure to set the index as
the primary key
- [[#7992](https://github.com/apache/incubator-seata/pull/7992)] fix report
branch transaction status without setting branch type
+- [[#8035](https://github.com/apache/incubator-seata/pull/8035)] fix
illegalArgumentException when GET request has request body
Review Comment:
Changelog entry uses `illegalArgumentException`; in Java the exception class
name is `IllegalArgumentException` (capital I/A/E). Consider updating the text
for consistency and readability.
```suggestion
- [[#8035](https://github.com/apache/incubator-seata/pull/8035)] fix
IllegalArgumentException when GET request has request body
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]