Merge pull request #12 from cprice404/bug/master/PE-5567-npe-if-no-charset
(PE-5567) Fix bug if content-type header has no charset
This commit is contained in:
commit
2a67e0b4b8
2 changed files with 22 additions and 2 deletions
|
@ -256,12 +256,12 @@ public class JavaClient {
|
|||
}
|
||||
}
|
||||
|
||||
private static Object coerceBodyType(InputStream body, ResponseBodyType as,
|
||||
public static Object coerceBodyType(InputStream body, ResponseBodyType as,
|
||||
ContentType contentType) {
|
||||
switch (as) {
|
||||
case TEXT:
|
||||
String charset = "UTF-8";
|
||||
if (contentType != null) {
|
||||
if ((contentType != null) && (contentType.getCharset() != null)) {
|
||||
charset = contentType.getCharset().name();
|
||||
}
|
||||
try {
|
||||
|
|
20
test/com/puppetlabs/http/client/impl/java_client_test.clj
Normal file
20
test/com/puppetlabs/http/client/impl/java_client_test.clj
Normal file
|
@ -0,0 +1,20 @@
|
|||
(ns com.puppetlabs.http.client.impl.java-client-test
|
||||
(:import (com.puppetlabs.http.client.impl JavaClient)
|
||||
(org.apache.commons.io IOUtils)
|
||||
(com.puppetlabs.http.client ResponseBodyType)
|
||||
(org.apache.http.entity ContentType))
|
||||
(:require [clojure.test :refer :all]))
|
||||
|
||||
;; NOTE: there are more comprehensive, end-to-end tests for
|
||||
;; the Java client functionality lumped in with the clojure
|
||||
;; tests. This namespace is just for some edge-casey,
|
||||
;; Java-only unit tests.
|
||||
|
||||
(deftest test-coerce-body-type
|
||||
(testing "Can handle a Content Type header with no charset"
|
||||
(let [body "foo"
|
||||
body-stream (IOUtils/toInputStream body "UTF-8")]
|
||||
(is (= "foo" (JavaClient/coerceBodyType
|
||||
body-stream
|
||||
ResponseBodyType/TEXT
|
||||
ContentType/WILDCARD))))))
|
Loading…
Reference in a new issue