Skip to content

Commit

Permalink
Handle content-type with charset.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
spencergibb committed Jan 25, 2017
1 parent ca244c5 commit d76bd84
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -275,9 +276,21 @@ private HttpResponse forward(HttpClient httpclient, String verb, String uri,
HttpHost httpHost = getHttpHost(host);
uri = StringUtils.cleanPath((host.getPath() + uri).replaceAll("/{2,}", "/"));
int contentLength = request.getContentLength();
InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength,
request.getContentType() != null
? ContentType.create(request.getContentType()) : null);

ContentType contentType = 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);
try {
Expand Down Expand Up @@ -409,4 +422,4 @@ protected void addIgnoredHeaders(String... names) {
boolean isSslHostnameValidationEnabled() {
return this.sslHostnameValidationEnabled;
}
}
}

0 comments on commit d76bd84

Please sign in to comment.