|
13 | 13 | [ring.util.codec :refer [form-decode-str]]
|
14 | 14 | [slingshot.slingshot :refer [try+]])
|
15 | 15 | (:import java.io.ByteArrayInputStream
|
16 |
| - java.io.PipedInputStream |
17 |
| - java.io.PipedOutputStream |
18 | 16 | java.net.UnknownHostException
|
19 | 17 | org.apache.http.HttpEntity
|
20 | 18 | org.apache.logging.log4j.LogManager))
|
|
28 | 26 | :server-name "localhost"
|
29 | 27 | :server-port 18080})
|
30 | 28 |
|
31 |
| -#_ |
32 |
| -(defn request |
33 |
| - ([req] |
34 |
| - (client/request (merge base-req req))) |
35 |
| - ([req respond raise] |
36 |
| - (client/request (merge base-req req) respond raise))) |
37 |
| - |
38 | 29 | (defn parse-form-params [s]
|
39 | 30 | (->> (str/split (form-decode-str s) #"&")
|
40 | 31 | (map #(str/split % #"="))
|
|
1760 | 1751 | (is (= (.getMessage e)
|
1761 | 1752 | (str "only :flatten-nested-keys or :ignore-nested-query-string/"
|
1762 | 1753 | ":flatten-nested-keys may be specified, not both"))))))
|
1763 |
| - |
1764 |
| -(defn transit-resp [body] |
1765 |
| - {:body body |
1766 |
| - :status 200 |
1767 |
| - :headers {"content-type" "application/transit-json"}}) |
1768 |
| - |
1769 |
| -(deftest issue-609-empty-transit-response |
1770 |
| - (testing "Body is available right away" |
1771 |
| - (is (= {:foo "bar"} |
1772 |
| - (:body (client/coerce-response-body |
1773 |
| - {:as :transit+json} |
1774 |
| - (transit-resp (ByteArrayInputStream. |
1775 |
| - (.getBytes "[\"^ \",\"~:foo\",\"bar\"]")))))))) |
1776 |
| - |
1777 |
| - (testing "Empty body is read as nil" |
1778 |
| - (is (nil? (:body (client/coerce-response-body |
1779 |
| - {:as :transit+json} |
1780 |
| - (transit-resp (ByteArrayInputStream. (.getBytes "")))))))) |
1781 |
| - |
1782 |
| - (testing "Body is read correctly even if the data becomes available later" |
1783 |
| - ;; Ensure both streams are closed (normally done inside future). |
1784 |
| - (with-open [o (PipedOutputStream.) |
1785 |
| - i (PipedInputStream.)] |
1786 |
| - (.connect i o) |
1787 |
| - (future |
1788 |
| - (Thread/sleep 10) |
1789 |
| - (.write o (.getBytes "[\"^ \",\"~:foo\",\"bar\"]")) |
1790 |
| - ;; Close right now, with-open will wait until test is done. |
1791 |
| - (.close o)) |
1792 |
| - (is (= {:foo "bar"} |
1793 |
| - (:body (client/coerce-response-body |
1794 |
| - {:as :transit+json} |
1795 |
| - (transit-resp i)))))))) |
0 commit comments