Handle content-type with charset.

A new version of httpclient introduced by boot changed the behaviour that previously allowed the charset. It now has to be parsed out and passed to the apache `ContentType` object explicitly. fixes gh-1649
parent ca244c5d
...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.zuul.filters.route; ...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.zuul.filters.route;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
...@@ -275,9 +276,21 @@ public class SimpleHostRoutingFilter extends ZuulFilter { ...@@ -275,9 +276,21 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
HttpHost httpHost = getHttpHost(host); HttpHost httpHost = getHttpHost(host);
uri = StringUtils.cleanPath((host.getPath() + uri).replaceAll("/{2,}", "/")); uri = StringUtils.cleanPath((host.getPath() + uri).replaceAll("/{2,}", "/"));
int contentLength = request.getContentLength(); int contentLength = request.getContentLength();
InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength,
request.getContentType() != null ContentType contentType = null;
? ContentType.create(request.getContentType()) : null);
if (request.getContentType() != null) {
String contentTypeString = request.getContentType();
Charset charset = null;
if (contentTypeString.contains(";charset=")) {
final String[] split = contentTypeString.split(";charset=");
contentTypeString = split[0];
charset = Charset.forName(split[1]);
}
contentType = ContentType.create(contentTypeString, charset);
}
InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength, contentType);
HttpRequest httpRequest = buildHttpRequest(verb, uri, entity, headers, params, request); HttpRequest httpRequest = buildHttpRequest(verb, uri, entity, headers, params, request);
try { try {
...@@ -409,4 +422,4 @@ public class SimpleHostRoutingFilter extends ZuulFilter { ...@@ -409,4 +422,4 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
boolean isSslHostnameValidationEnabled() { boolean isSslHostnameValidationEnabled() {
return this.sslHostnameValidationEnabled; return this.sslHostnameValidationEnabled;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment