Pārlūkot izejas kodu

Fix content-type parsing bug in transport module and support UTF-8 encoding in SentinelApiClient (#1207)

* Fix content-type parsing bug in `sentinel-transport-simple-http` module
* Change the charset of UrlEncodedFormEntity to UTF-8 in SentinelApiClient of the dashboard to support non-ASCII characters
master
zhenxianyimeng Eric Zhao pirms 5 gadiem
vecāks
revīzija
50f3080add
2 mainītis faili ar 6 papildinājumiem un 6 dzēšanām
  1. +2
    -6
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java
  2. +4
    -0
      sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java

+ 2
- 6
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java Parādīt failu

@@ -62,6 +62,7 @@ import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;

import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
@@ -175,12 +176,7 @@ public class SentinelApiClient {
for (Entry<String, String> entry : params.entrySet()) {
list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
try {
httpPost.setEntity(new UrlEncodedFormEntity(list));
} catch (UnsupportedEncodingException e) {
logger.warn("httpPostContent encode entity error: {}", params, e);
return null;
}
httpPost.setEntity(new UrlEncodedFormEntity(list, Consts.UTF_8));
}
return httpPost;
}


+ 4
- 0
sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java Parādīt failu

@@ -113,6 +113,10 @@ public class HttpEventTask implements Runnable {
String headerName = bodyLine.substring(0, index);
String header = bodyLine.substring(index + 1).trim();
if (StringUtil.equalsIgnoreCase("content-type", headerName)) {
int idx = header.indexOf(";");
if (idx > 0){
header = header.substring(0, idx).trim();
}
if (StringUtil.equals("application/x-www-form-urlencoded", header)) {
supported = true;
} else {


Notiek ielāde…
Atcelt
Saglabāt