(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();
|
charset = contentType.getCharset().name();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (body == null){
|
||||||
|
response = "";
|
||||||
|
}
|
||||||
|
else{
|
||||||
response = IOUtils.toString(body, charset);
|
response = IOUtils.toString(body, charset);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpClientException("Unable to read body as string", e);
|
throw new HttpClientException("Unable to read body as string", e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (body != null){
|
||||||
body.close();
|
body.close();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpClientException(
|
throw new HttpClientException(
|
||||||
"Unable to close response stream", e);
|
"Unable to close response stream", e);
|
||||||
|
|
|
@ -52,3 +52,9 @@
|
||||||
(let [body "foo"]
|
(let [body "foo"]
|
||||||
(is (= (compute-content-type body "text/html")
|
(is (= (compute-content-type body "text/html")
|
||||||
"text/html; charset=UTF-8")))))))
|
"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