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
This commit is contained in:
parent
a63c1841ee
commit
50f3080add
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue