Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn- handle-response
- "Handles an http response, and reformats it into a dictionary"
- [^HttpResponse response & {:keys [slurp-stream?] :or {slurp-stream? true}}]
- (let [entity (.getEntity response)
- status (.getStatusLine response)]
- {:entity (if entity
- (let [content-stream (.getContent entity)
- content-length (.getContentLength entity)
- content-type (.getContentType entity)]
- {:stream content-stream
- :content (if (and content-stream slurp-stream?)
- (do (slurp content-stream)
- (println "Slurped Stream")))
- :length content-length
- :content-type (if content-type (.getValue content-type))}))
- :status (if status
- (let [protocol (.getProtocolVersion status)
- reason (.getReasonPhrase status)
- code (.getStatusCode status)]
- {:protocol protocol
- :reason reason
- :code code}))}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement