Skip to content

Commit bd14bdc

Browse files
committed
Flush output stream when body is written.
1 parent f94872d commit bd14bdc

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/clojure/http/client.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:use [clojure.contrib.java-utils :only [as-str]]
33
[clojure.contrib.duck-streams :only [read-lines writer]]
44
[clojure.contrib.str-utils :only [str-join]])
5-
(:import (java.net URL HttpURLConnection URLEncoder)
5+
(:import (java.net URL URLEncoder)
66
(java.io StringReader)))
77

88
(def default-headers {"User-Agent" (str "Clojure/" (clojure-version)
@@ -82,7 +82,7 @@ by a server."
8282
(first header)
8383
(second header)))
8484

85-
(when cookies
85+
(when (and cookies (not (empty? cookies)))
8686
(.setRequestProperty connection
8787
"Cookie"
8888
(create-cookie-string cookies)))
@@ -93,10 +93,9 @@ by a server."
9393
"Content-Type"
9494
"application/x-www-form-urlencoded")
9595
(.connect connection)
96-
(.write (writer (.getOutputStream connection))
97-
(if (isa? body String)
98-
body
99-
(encode-body-map body))))
96+
(with-open [out (writer (.getOutputStream connection))]
97+
(.write out "{ hello: \"world\" }")
98+
(.flush out)))
10099
(.connect connection))
101100

102101
(let [headers (parse-headers connection)]

0 commit comments

Comments
 (0)