Skip to content

Commit b24248d

Browse files
author
Stephane Landelle
committed
Minor clean: align calculateCharset on 1.9 and return a Charset
1 parent 6ce7832 commit b24248d

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

api/src/main/java/org/asynchttpclient/providers/ResponseBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import org.asynchttpclient.uri.Uri;
1212
import org.asynchttpclient.util.AsyncHttpProviderUtils;
1313

14+
import java.nio.charset.Charset;
1415
import java.util.Collections;
1516
import java.util.List;
1617

1718
public abstract class ResponseBase implements Response {
18-
protected final static String DEFAULT_CHARSET = "ISO-8859-1";
1919

2020
protected final List<HttpResponseBodyPart> bodyParts;
2121
protected final HttpResponseHeaders headers;
@@ -30,14 +30,14 @@ protected ResponseBase(HttpResponseStatus status, HttpResponseHeaders headers, L
3030

3131
protected abstract List<Cookie> buildCookies();
3232

33-
protected String calculateCharset(String charset) {
33+
protected Charset calculateCharset(String charset) {
3434

3535
if (charset == null) {
3636
String contentType = getContentType();
3737
if (contentType != null)
3838
charset = AsyncHttpProviderUtils.parseCharset(contentType); // parseCharset can return null
3939
}
40-
return charset != null ? charset : DEFAULT_CHARSET;
40+
return charset != null ? Charset.forName(charset) : AsyncHttpProviderUtils.DEFAULT_CHARSET;
4141
}
4242

4343
@Override

providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public InputStream getResponseBodyAsStream() throws IOException {
6969
* {@inheritDoc}
7070
*/
7171
public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException {
72-
charset = calculateCharset(charset);
7372
final Buffer responseBody = getResponseBody0();
7473
final int len = Math.min(responseBody.remaining(), maxLength);
7574
final int pos = responseBody.position();

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/response/NettyResponse.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ public String getResponseBodyExcerpt(int maxLength) throws IOException {
4949
}
5050

5151
public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException {
52-
// should be fine; except that it may split multi-byte chars (last char may become '?')
53-
charset = calculateCharset(charset);
5452
byte[] b = contentToBytes(bodyParts, maxLength);
55-
return new String(b, charset);
53+
// should be fine; except that it may split multi-byte chars (last char may become '?')
54+
return new String(b, calculateCharset(charset));
5655
}
5756

5857
protected List<Cookie> buildCookies() {

0 commit comments

Comments
 (0)