Skip to content

Commit 27e6053

Browse files
author
Stephane Landelle
committed
Fix charset computation when it's not specified in contentType
1 parent 39cb971 commit 27e6053

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/main/java/com/ning/http/client/providers/apache/ApacheResponse.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,12 @@ public String getResponseBodyExcerpt(int maxLength, String charset) throws IOExc
104104
}
105105

106106
private String computeCharset(String charset) {
107-
String contentType = getContentType();
108107
if (charset == null) {
108+
String contentType = getContentType();
109109
if (contentType != null)
110-
charset = AsyncHttpProviderUtils.parseCharset(contentType);
111-
else
112-
charset = DEFAULT_CHARSET;
110+
charset = AsyncHttpProviderUtils.parseCharset(contentType); // parseCharset can return null
113111
}
114-
return charset;
112+
return charset != null? charset: DEFAULT_CHARSET;
115113
}
116114

117115
/* @Override */

src/main/java/com/ning/http/client/providers/jdk/JDKResponse.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,12 @@ public String getResponseBodyExcerpt(int maxLength, String charset) throws IOExc
117117
}
118118

119119
private String computeCharset(String charset) {
120-
String contentType = getContentType();
121120
if (charset == null) {
121+
String contentType = getContentType();
122122
if (contentType != null)
123-
charset = AsyncHttpProviderUtils.parseCharset(contentType);
124-
else
125-
charset = DEFAULT_CHARSET;
123+
charset = AsyncHttpProviderUtils.parseCharset(contentType); // parseCharset can return null
126124
}
127-
return charset;
125+
return charset != null? charset: DEFAULT_CHARSET;
128126
}
129127

130128
/* @Override */

src/main/java/com/ning/http/client/providers/netty/NettyResponse.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,12 @@ public String getResponseBodyExcerpt(int maxLength, String charset) throws IOExc
111111
}
112112

113113
private String computeCharset(String charset) {
114-
String contentType = getContentType();
115114
if (charset == null) {
115+
String contentType = getContentType();
116116
if (contentType != null)
117-
charset = AsyncHttpProviderUtils.parseCharset(contentType);
118-
else
119-
charset = DEFAULT_CHARSET;
117+
charset = AsyncHttpProviderUtils.parseCharset(contentType); // parseCharset can return null
120118
}
121-
return charset;
119+
return charset != null? charset: DEFAULT_CHARSET;
122120
}
123121

124122
/* @Override */

0 commit comments

Comments
 (0)