Skip to content

Commit

Permalink
test and fix input coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgrana committed Aug 7, 2010
1 parent 4aff0bc commit 0975906
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/clj_http/client.clj
Expand Up @@ -75,7 +75,7 @@
(defn wrap-input-coercion [client]
(fn [{:keys [body] :as req}]
(if (string? body)
(client (-> req (assoc :body (.toString body "UTF-8")
(client (-> req (assoc :body (.getBytes body "UTF-8")
:character-encoding "UTF-8")))
(client req))))

Expand Down
14 changes: 13 additions & 1 deletion test/clj_http/client_test.clj
@@ -1,7 +1,8 @@
(ns clj-http.client-test
(:use clojure.test)
(:require [clj-http.client :as client])
(:require [clj-http.util :as util]))
(:require [clj-http.util :as util])
(:import (java.util Arrays)))

(def base-req
{:scheme "http"
Expand Down Expand Up @@ -113,6 +114,17 @@
{:uri "/foo"}))


(deftest apply-on-input-coercion
(let [i-client (client/wrap-input-coercion identity)
resp (i-client {:body "foo"})]
(is (= "UTF-8" (:character-encoding resp)))
(is (Arrays/equals (.getBytes "foo" "UTF-8") (:body resp)))))

(deftest pass-on-no-input-coercion
(is-passed client/wrap-input-coercion
{:body (.getBytes "foo" "UTF-8")}))


(deftest apply-on-content-type
(is-applied client/wrap-content-type
{:content-type :json}
Expand Down

0 comments on commit 0975906

Please sign in to comment.