From 50f3080add8ef08350060064ddd3e8ea78503013 Mon Sep 17 00:00:00 2001 From: zhenxianyimeng <1920405993@qq.com> Date: Thu, 19 Dec 2019 20:50:20 +0800 Subject: [PATCH] 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 --- .../csp/sentinel/dashboard/client/SentinelApiClient.java | 8 ++------ .../sentinel/transport/command/http/HttpEventTask.java | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java index ec27e26c..79e44818 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java @@ -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 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; } diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java index 80df0955..1c36ec86 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java @@ -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 {