diff --git a/project.clj b/project.clj index a742fa6..f30f1d4 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject tailrecursion/ring-proxy "2.0.0-SNAPSHOT" +(defproject tailrecursion/ring-proxy "2.0.1-SNAPSHOT" :description "HTTP proxy ring middleware for Clojure web applications." :url "https://github.com/tailrecursion/ring-proxy" :license {:name "Eclipse Public License" diff --git a/src/tailrecursion/ring_proxy.clj b/src/tailrecursion/ring_proxy.clj index 9759b98..5e641fd 100644 --- a/src/tailrecursion/ring_proxy.clj +++ b/src/tailrecursion/ring_proxy.clj @@ -22,6 +22,20 @@ (.read rdr buf) buf))) +(defn forward-request + "Forward request to the specified remote-uri" + [req remote-uri & [http-opts]] + (-> (merge {:method (:request-method req) + :url (str remote-uri "?" (:query-string req)) + :headers (dissoc (:headers req) "host" "content-length") + :body (if-let [len (get-in req [:headers "content-length"])] + (slurp-binary (:body req) (Integer/parseInt len))) + :follow-redirects true + :throw-exceptions false + :as :stream} http-opts) + request + prepare-cookies)) + (defn wrap-proxy "Proxies requests to proxied-path, a local URI, to the remote URI at remote-uri-base, also a string." @@ -36,16 +50,7 @@ (subs (:uri req) (.length proxied-path))) nil nil)] - (-> (merge {:method (:request-method req) - :url (str remote-uri "?" (:query-string req)) - :headers (dissoc (:headers req) "host" "content-length") - :body (if-let [len (get-in req [:headers "content-length"])] - (slurp-binary (:body req) (Integer/parseInt len))) - :follow-redirects true - :throw-exceptions false - :as :stream} http-opts) - request - prepare-cookies)) + (forward-request req remote-uri [http-opts])) (handler req))))) (defn local-proxy-server