Browse files

Type hints in core.clj

Most of these are for HttpURLConnection, with one InputStream exception.
This silences the rest of the warnings existing in clj-http-lite proper.
  • Loading branch information...
toofishes committed Oct 16, 2012
1 parent 083d861 commit 71065f9a1b3e8909c5843d8112cde6b4cec453b4
Showing with 10 additions and 10 deletions.
  1. +10 −10 src/clj_http/lite/core.clj
@@ -1,8 +1,8 @@
(ns clj-http.lite.core
"Core HTTP request/response implementation."
(:require [ :as io])
- (:import ( ByteArrayOutputStream IOException)
- ( URI URL)))
+ (:import ( ByteArrayOutputStream InputStream IOException)
+ ( URI URL HttpURLConnection)))
(defn parse-headers
"Takes a URLConnection and returns a map of names to values.
@@ -12,12 +12,12 @@
in the headers."
(loop [i 1 headers {}]
- (let [k (.getHeaderFieldKey conn i)
- v (.getHeaderField conn i)]
+ (let [k (.getHeaderFieldKey ^HttpURLConnection conn i)
+ v (.getHeaderField ^HttpURLConnection conn i)]
(if k
(recur (inc i) (update-in headers [k] conj v))
(zipmap (for [k (keys headers)]
- (.toLowerCase k))
+ (.toLowerCase ^String k))
(for [v (vals headers)]
(if (= 1 (count v))
(first v)
@@ -28,12 +28,12 @@
stream that closes itself and the connection manager when closed."
[{:keys [as]} conn]
(let [ins (try
- (.getInputStream conn)
+ (.getInputStream ^HttpURLConnection conn)
(catch Exception e
- (.getErrorStream conn)))]
+ (.getErrorStream ^HttpURLConnection conn)))]
(if (= :stream as)
- (with-open [ins ins
+ (with-open [ins ^InputStream ins
baos (ByteArrayOutputStream.)]
(io/copy ins baos)
(.flush baos)
@@ -61,7 +61,7 @@
(.setRequestProperty conn "Content-Type" content-type))
(doseq [[h v] headers]
(.setRequestProperty conn h v))
- (.setRequestMethod conn (.toUpperCase (name request-method)))
+ (.setRequestMethod ^HttpURLConnection conn (.toUpperCase (name request-method)))
(when body
(.setDoOutput conn true))
(when socket-timeout
@@ -71,7 +71,7 @@
(with-open [out (.getOutputStream conn)]
(io/copy body out)))
(merge {:headers (parse-headers conn)
- :status (.getResponseCode conn)
+ :status (.getResponseCode ^HttpURLConnection conn)
:body (when-not (= request-method :head)
(coerce-body-entity req conn))}
(when save-request?

0 comments on commit 71065f9

Please sign in to comment.