Advertisement
Guest User

Untitled

a guest
Jul 8th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn- handle-response
  2.   "Handles an http response, and reformats it into a dictionary"
  3.   [^HttpResponse response & {:keys [slurp-stream?] :or {slurp-stream? true}}]
  4.   (let [entity (.getEntity response)
  5.         status (.getStatusLine response)]
  6.     {:entity (if entity
  7.                (let [content-stream (.getContent entity)
  8.                      content-length (.getContentLength entity)
  9.                      content-type (.getContentType entity)]
  10.                  {:stream content-stream
  11.                   :content (if (and content-stream slurp-stream?)
  12.                              (do (slurp content-stream)
  13.                                  (println "Slurped Stream")))
  14.                   :length content-length
  15.                   :content-type (if content-type (.getValue content-type))}))
  16.      :status (if status
  17.                (let [protocol (.getProtocolVersion status)
  18.                      reason (.getReasonPhrase status)
  19.                      code (.getStatusCode status)]
  20.                  {:protocol protocol
  21.                   :reason reason
  22.                   :code code}))}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement