tailrecursion / ring-proxy

HTTP proxy ring middleware for Clojure web applications.
47 stars 14 forks source link

Issue when passing headers with http-opts #7

Open deanmarano opened 10 years ago

deanmarano commented 10 years ago

When you specify headers, it doesn't do a deep merge, and the specified headers are the ONLY ones passed along.

https://github.com/tailrecursion/ring-proxy/blob/master/src/tailrecursion/ring_proxy.clj#L45

For example, I'm using this to add a AUTH_TOKEN header with the proxy. The request comes in with Content-Type: application/json, but after this merge only the overrides exist.

One fix would be to do (merge-with merge req http-opts), which handles one level of nested (which will always be the case with http-opts).

micha commented 10 years ago

I wonder if we can solve this problem decisively by somehow providing a hook into the merging process itself, like perhaps by accepting a function that will perform the merging? I'm imagining changing the signature of wrap-proxy like this:

(defn wrap-proxy
  [handler proxied-path remote-uri-base & {:keys [merge-with] :as http-opts}]
  (let [http-opts (dissoc http-opts :merge-with)
        merge-with (or merge-with merge)
        ... ]
   ...))