commit - a7994c56b79eb7bc0d8880c112de608699fd5389
commit + 5243b9aceebf16eddceeddac17b1f24ebae3078d
blob - 2f39cb481670653e001d63e927df8ab18fa8ff3c
blob + 433d9d6f88de57d8f81b651ec51f38fe0d2de6db
--- src/gemini/core.clj
+++ src/gemini/core.clj
(ns gemini.core
(:require
[clojure.java.io :as io])
- (:import (com.omarpolo.gemini Request)))
+ (:import
+ (com.omarpolo.gemini Request)))
(defmacro ^:private request->map [& args]
`(try
([host port uri]
(request->map host port uri)))
-(defn body-as-string! [{r :request}]
+(defn body-as-string!
"Read all the response into a strings and returns it. The request
will be closed."
+ [{r :request}]
(let [sw (java.io.StringWriter.)]
(with-open [r r]
(io/copy (.body r) sw)
(.toString sw))))
-(defn close [{r :request}]
+(defn close
+ "Close a request."
+ [{r :request}]
(.close r))
-(defmacro with-request [[var req] & body]
+(defmacro with-request
"Make a request, eval `body` when it succeed and automatically close
- the request, or throw an exception if the request fails."
+ the request, or throw an exception if the request fails."
+ [[var req] & body]
`(let [~var ~req]
(when-let [e# (:error ~var)]
(throw e#))