From 28f8c4c0b40a0d9e95b3126bed87cf06948b35a1 Mon Sep 17 00:00:00 2001 From: Dean Marano Date: Tue, 18 Mar 2014 16:03:48 -0500 Subject: [PATCH 1/2] Allow proxying of multi packet data. --- src/tailrecursion/ring_proxy.clj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tailrecursion/ring_proxy.clj b/src/tailrecursion/ring_proxy.clj index dfe5c1a..b7fe3c1 100644 --- a/src/tailrecursion/ring_proxy.clj +++ b/src/tailrecursion/ring_proxy.clj @@ -18,8 +18,10 @@ [^java.io.InputStream is len] (with-open [rdr is] (let [buf (byte-array len)] - (.read rdr buf) - buf))) + (loop [bytes-read (.read rdr buf)] + (if (= bytes-read -1) + buf + (recur (.read rdr buf))))))) (defn wrap-proxy "Proxies requests to proxied-path, a local URI, to the remote URI at From 9cd2871c7120fa56b29fcdf96560c9638c2b5da7 Mon Sep 17 00:00:00 2001 From: Dean Marano Date: Tue, 25 Mar 2014 16:42:45 -0500 Subject: [PATCH 2/2] Bump version, deep merge options hash. --- project.clj | 5 +++-- src/tailrecursion/ring_proxy.clj | 9 ++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/project.clj b/project.clj index bde89ff..3e137a6 100644 --- a/project.clj +++ b/project.clj @@ -1,8 +1,9 @@ -(defproject tailrecursion/ring-proxy "2.0.0-SNAPSHOT" +(defproject tailrecursion/ring-proxy "4.0.2-FINAL" :description "HTTP proxy ring middleware for Clojure web applications." :url "https://github.com/tailrecursion/ring-proxy" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.4.0"] [ring/ring-core "1.1.8"] - [clj-http "0.6.5"]]) + [clj-http "0.6.5"]] +:repositories [["releases" {:url "http://nexus-dev.snc1/content/repositories/releases/" :sign-releases false}]]) diff --git a/src/tailrecursion/ring_proxy.clj b/src/tailrecursion/ring_proxy.clj index b7fe3c1..631b50e 100644 --- a/src/tailrecursion/ring_proxy.clj +++ b/src/tailrecursion/ring_proxy.clj @@ -16,12 +16,7 @@ (defn slurp-binary "Reads len bytes from InputStream is and returns a byte array." [^java.io.InputStream is len] - (with-open [rdr is] - (let [buf (byte-array len)] - (loop [bytes-read (.read rdr buf)] - (if (= bytes-read -1) - buf - (recur (.read rdr buf))))))) + (slurp is)) (defn wrap-proxy "Proxies requests to proxied-path, a local URI, to the remote URI at @@ -37,7 +32,7 @@ (subs (:uri req) (.length proxied-path))) nil nil)] - (-> (merge {:method (:request-method req) + (-> (merge-with 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"])]