Merge pull request #40 from jpinsonault/tk-182-illegal-arg-exception-on-204-response
(TK-182) Illegal argument exception on 204 response
This commit is contained in:
commit
146d2fb4bc
4 changed files with 24 additions and 3 deletions
|
@ -199,7 +199,9 @@
|
||||||
(defmethod coerce-body-type :text
|
(defmethod coerce-body-type :text
|
||||||
[resp]
|
[resp]
|
||||||
(let [charset (or (get-in resp [:content-type-params :charset] "UTF-8"))]
|
(let [charset (or (get-in resp [:content-type-params :charset] "UTF-8"))]
|
||||||
(assoc resp :body (slurp (:body resp) :encoding charset))))
|
(assoc resp :body (if (:body resp)
|
||||||
|
(slurp (:body resp) :encoding charset)
|
||||||
|
""))))
|
||||||
|
|
||||||
(defn- response-map
|
(defn- response-map
|
||||||
[opts http-response]
|
[opts http-response]
|
||||||
|
|
|
@ -425,12 +425,19 @@ public class JavaClient {
|
||||||
charset = contentType.getCharset().name();
|
charset = contentType.getCharset().name();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
response = IOUtils.toString(body, charset);
|
if (body == null){
|
||||||
|
response = "";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
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 {
|
||||||
body.close();
|
if (body != null){
|
||||||
|
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))))))
|
||||||
|
|
|
@ -29,3 +29,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 nil-response-body-coerced-as-text
|
||||||
|
(testing "a nil response body is coerced into a string by async/coerce-body-type"
|
||||||
|
(let [resp {:body nil, :opts {:as :text}}]
|
||||||
|
(is (= {:body "", :opts {:as :text}}
|
||||||
|
(coerce-body-type resp))))))
|
||||||
|
|
Loading…
Reference in a new issue