Skip to content

Commit

Permalink
Wrongly setting Content-Encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Sep 8, 2018
1 parent 9451f19 commit eba4565
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions jena-arq/src/main/java/org/apache/jena/riot/web/HttpOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public static TypedInputStream execHttpPostStream(String url, String contentType
* HTTP Context
*/
public static void execHttpPost(String url, String contentType, String content, String acceptType,
HttpResponseHandler handler, HttpClient httpClient, HttpContext httpContext) {
HttpResponseHandler handler, HttpClient httpClient, HttpContext httpContext) {
StringEntity e = null;
try {
e = new StringEntity(content, StandardCharsets.UTF_8);
Expand Down Expand Up @@ -557,7 +557,7 @@ public static void execHttpPost(String url, String contentType, InputStream inpu
* Response handler called to process the response
*/
public static void execHttpPost(String url, String contentType, InputStream input, long length, String acceptType,
HttpResponseHandler handler) {
HttpResponseHandler handler) {
execHttpPost(url, contentType, input, length, acceptType, handler, null, null);
}

Expand Down Expand Up @@ -587,17 +587,17 @@ public static void execHttpPost(String url, String contentType, InputStream inpu
*
*/
public static void execHttpPost(String url, String contentType, InputStream input, long length, String acceptType,
HttpResponseHandler handler, HttpClient httpClient, HttpContext httpContext) {
HttpResponseHandler handler, HttpClient httpClient, HttpContext httpContext) {
InputStreamEntity e = new InputStreamEntity(input, length);
e.setContentType(contentType);
e.setContentEncoding("UTF-8");
String ct = decideContentType(contentType);
e.setContentType(ct);
try {
execHttpPost(url, e, acceptType, handler, httpClient, httpContext);
} finally {
closeEntity(e);
}
}

/**
* Executes a HTTP POST of the given entity
*
Expand Down Expand Up @@ -932,8 +932,8 @@ public static void execHttpPut(String url, String contentType, InputStream input
public static void execHttpPut(String url, String contentType, InputStream input, long length, HttpClient httpClient,
HttpContext httpContext) {
InputStreamEntity e = new InputStreamEntity(input, length);
e.setContentType(contentType);
e.setContentEncoding("UTF-8");
String ct = decideContentType(contentType);
e.setContentType(ct);
try {
execHttpPut(url, e, httpClient, httpContext);
} finally {
Expand Down Expand Up @@ -1129,6 +1129,16 @@ private static void closeEntity(HttpEntity entity) {
}
}

/**
* Content-Type, ensuring charset is present, defaulting to UTF-8.
*/
private static String decideContentType(String contentType) {
String ct = contentType;
if ( ct != null && ! ct.contains("charset=") )
ct = ct+"; charset=UTF-8";
return ct;
}

/**
* Calculate the request URI from a general URI. This means remove any
* fragment.
Expand Down

0 comments on commit eba4565

Please sign in to comment.