(MAINT) Added fix/test for java coerceBodyType
This commit is contained in:
parent
08ca923e69
commit
c5489e0e43
2 changed files with 15 additions and 2 deletions
|
@ -425,12 +425,19 @@ public class JavaClient {
|
|||
charset = contentType.getCharset().name();
|
||||
}
|
||||
try {
|
||||
response = IOUtils.toString(body, charset);
|
||||
if (body == null){
|
||||
response = "";
|
||||
}
|
||||
else{
|
||||
response = IOUtils.toString(body, charset);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("Unable to read body as string", e);
|
||||
}
|
||||
try {
|
||||
body.close();
|
||||
if (body != null){
|
||||
body.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException(
|
||||
"Unable to close response stream", e);
|
||||
|
|
|
@ -52,3 +52,9 @@
|
|||
(let [body "foo"]
|
||||
(is (= (compute-content-type body "text/html")
|
||||
"text/html; charset=UTF-8")))))))
|
||||
|
||||
|
||||
(deftest null-response-body-coerced-as-text
|
||||
(testing "a null response body is coerced into a string by JavaClient.coerceBodyType"
|
||||
(let [body nil]
|
||||
(is (= "" (JavaClient/coerceBodyType body ResponseBodyType/TEXT nil))))))
|
||||
|
|
Loading…
Reference in a new issue