Skip to content

Commit

Permalink
Merge pull request #2550 from nkorange/hotfix_client_beat_lost_in_red…
Browse files Browse the repository at this point in the history
…irect

Hotfix client beat lost in redirect
  • Loading branch information
nkorange authored Mar 31, 2020
2 parents 74e34ea + a74d057 commit fea9e2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static HttpResult request(String url, List<String> headers, Map<String, S
HttpURLConnection conn = null;
try {
String encodedContent = encodingParams(paramValues, encoding);
url += (null == encodedContent) ? "" : ("?" + encodedContent);
url += StringUtils.isBlank(encodedContent) ? StringUtils.EMPTY : ("?" + encodedContent);

conn = (HttpURLConnection) new URL(url).openConnection();
conn.setConnectTimeout(connectTimeout);
Expand Down Expand Up @@ -257,7 +257,7 @@ public static HttpResult httpPost(String url, List<String> headers, Map<String,
HeaderElement[] headerElements = entity.getContentType().getElements();

if (headerElements != null && headerElements.length > 0 && headerElements[0] != null &&
headerElements[0].getParameterByName("charset") != null) {
headerElements[0].getParameterByName("charset") != null) {
charset = headerElements[0].getParameterByName("charset").getValue();
}
}
Expand Down Expand Up @@ -392,7 +392,7 @@ public static HttpResult httpPostLarge(String url, Map<String, String> headers,
String charset = headerElements[0].getParameterByName("charset").getValue();

return new HttpResult(response.getStatusLine().getStatusCode(),
IoUtils.toString(entity.getContent(), charset), Collections.<String, String>emptyMap());
IoUtils.toString(entity.getContent(), charset), Collections.<String, String>emptyMap());
} catch (Exception e) {
return new HttpResult(500, e.toString(), Collections.<String, String>emptyMap());
}
Expand Down Expand Up @@ -453,14 +453,14 @@ private static void setHeaders(HttpURLConnection conn, List<String> headers, Str
}

conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset="
+ encoding);
+ encoding);
conn.addRequestProperty("Accept-Charset", encoding);
conn.addRequestProperty(HttpHeaderConsts.CLIENT_VERSION_HEADER, VersionUtils.VERSION);
conn.addRequestProperty(HttpHeaderConsts.USER_AGENT_HEADER, UtilsAndCommons.SERVER_VERSION);
}

public static String encodingParams(Map<String, String> params, String encoding)
throws UnsupportedEncodingException {
throws UnsupportedEncodingException {
StringBuilder sb = new StringBuilder();
if (null == params || params.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;

/**
Expand Down Expand Up @@ -124,9 +123,9 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
String body = IoUtils.toString(req.getInputStream(), Charsets.UTF_8.name());

HttpClient.HttpResult result =
HttpClient.request("http://" + distroMapper.mapSrv(groupedServiceName) + urlString, headerList,
StringUtils.isBlank(req.getQueryString()) ? HttpClient.translateParameterMap(req.getParameterMap()) : new HashMap<>(2)
, body, PROXY_CONNECT_TIMEOUT, PROXY_READ_TIMEOUT, Charsets.UTF_8.name(), req.getMethod());
HttpClient.request("http://" + distroMapper.mapSrv(groupedServiceName) + req.getRequestURI(), headerList,
HttpClient.translateParameterMap(req.getParameterMap()),
body, PROXY_CONNECT_TIMEOUT, PROXY_READ_TIMEOUT, Charsets.UTF_8.name(), req.getMethod());

try {
resp.setCharacterEncoding("UTF-8");
Expand Down

0 comments on commit fea9e2d

Please sign in to comment.