            (org.apache.http.entity ByteArrayEntity StringEntity)
            (org.apache.http.impl.client BasicCredentialsProvider
                                         CloseableHttpClient HttpClients)
-           (org.apache.http.impl.conn PoolingHttpClientConnectionManager)))
+           (org.apache.http.impl.conn BasicHttpClientConnectionManager
+                                      PoolingHttpClientConnectionManager)))
+
+(defn parse-headers
+  "Takes a HeaderIterator and returns a map of names to values.
+
+  If a name appears more than once (like `set-cookie`) then the value
+  will be a vector containing the values in the order they appeared
+  in the headers."
+  [^HeaderIterator headers & [use-header-maps-in-response?]]
+  (if-not use-header-maps-in-response?
+    (->> (headers/header-iterator-seq headers)
+         (map (fn [[k v]]
+                [(.toLowerCase ^String k) v]))
+         (reduce (fn [hs [k v]]
+                   (headers/assoc-join hs k v))
+                 {}))
+    (->> (headers/header-iterator-seq headers)
+         (reduce (fn [hs [k v]]
+                   (headers/assoc-join hs k v))
+                 (headers/header-map)))))
 
 (defn http-route []
   ;; TODO add proxy support


(defn pooling-conn-mgr []
  (PoolingHttpClientConnectionManager. (registry-builder)))

(defn http-client [conn-mgr]
  (-> (HttpClients/custom)

           server-port
           request-method
           query-string
           conn-mgr
           uri]
    :as req}]
  (let [scheme (name scheme)
