   (:import java.net.URL)
   (:import clojure.lang.Keyword))
 
-(defn- merge-body
+(defn merge-bodies
+  "Merge the bodies of two responses together."
   [to from]
-  (if (and (string? to) (string? from))
-    (str to from)
-    (or to from)))
+  (if-let [from-body (:body from)]
+    (assoc to :body
+      (if (and (string? (:body to)) (string? from-body))
+        (str (:body to) from-body)
+        from-body))
+    to))
+
+(defn- merge-headers
+  "Merge headers from two responses together."
+  [to from]
+  (merge to (select-keys from [:headers])))
 
 (defn merge-response
   "Intelligently merge two response maps together."
   [to from]
-  (-> to
-    (merge from)
-    (assoc :headers (merge (:headers to) (:headers from)))
-    (assoc :body    (merge-body (:body to) (:body from)))))
+  (cond
+    (map? from)
+      (-> to (merge-headers from)
+             (merge-bodies from)
+             (merge (dissoc from :headers :body)))
+    (ifn? from)
+      (from to)))
 
 (defmulti response-from class)
 


(ns compojure.http.response
  (:use clojure.contrib.def)
  (:import clojure.lang.IPersistentVector)
  (:import java.util.Map)
  (:import clojure.lang.ISeq)

  "Create a new response map from a Clojure object, x."
  [x]
  (if-let [response (response-from x)]
    (merge-response default-response response)))
