From c9ac0c0275569360a135423bb9a15378dc97429e Mon Sep 17 00:00:00 2001 From: Timur Sungur Date: Thu, 16 Oct 2014 12:11:38 +0200 Subject: [PATCH 1/4] A function for single request forwarding --- src/tailrecursion/ring_proxy.clj | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tailrecursion/ring_proxy.clj b/src/tailrecursion/ring_proxy.clj index 9759b98..227ef2b 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." From 04b49a785534e0125a7fae7cf88e6aefbb2b700d Mon Sep 17 00:00:00 2001 From: Timur Sungur Date: Thu, 16 Oct 2014 15:37:59 +0200 Subject: [PATCH 2/4] Refactor: use forward-request in wrap-proxy --- src/tailrecursion/ring_proxy.clj | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/tailrecursion/ring_proxy.clj b/src/tailrecursion/ring_proxy.clj index 227ef2b..bc0353e 100644 --- a/src/tailrecursion/ring_proxy.clj +++ b/src/tailrecursion/ring_proxy.clj @@ -50,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)) (handler req))))) (defn local-proxy-server From 1f3afd59147dae37e02b4f0034f62d105f29496f Mon Sep 17 00:00:00 2001 From: Timur Sungur Date: Thu, 16 Oct 2014 15:42:21 +0200 Subject: [PATCH 3/4] Pass http-options to forward function --- src/tailrecursion/ring_proxy.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tailrecursion/ring_proxy.clj b/src/tailrecursion/ring_proxy.clj index bc0353e..5e641fd 100644 --- a/src/tailrecursion/ring_proxy.clj +++ b/src/tailrecursion/ring_proxy.clj @@ -50,7 +50,7 @@ (subs (:uri req) (.length proxied-path))) nil nil)] - (forward-request req remote-uri)) + (forward-request req remote-uri [http-opts])) (handler req))))) (defn local-proxy-server From 698cb2bb3195dc506dd86f2f05ef6dda2acb6066 Mon Sep 17 00:00:00 2001 From: timur Date: Thu, 5 Feb 2015 17:01:02 +0100 Subject: [PATCH 4/4] Update version --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"