   (fn [request]
     ((creator) request)))
 
+(defn lazy-handler
+  "Wraps a handler creator function such that the root handler is created lazily on first access."
+  {:added "0.1.28"}
+  [creator]
+  (let [handler (delay (creator))]
+    (fn [request]
+      (@handler request))))
+
 (defn wrap-log-request
   "Logs incoming requests (as info), identifying method and URI."
   [handler]


  The extra middleware is added around the root handler (or the
  reloading handler that creates the root handler)."
  [{:keys [reload log debug track standard exceptions]} creator & creator-args]
  (let [creator' (wrap-creator creator creator-args)
        handler (if reload
                  (reloading-handler creator')
                  ;; Or just do it once, right now.
                  (creator'))]
    (cond-> handler

            (assoc :body (io/input-stream body-array))
            handler)))))

(defn- log-response
  "Logs the response at debug level (if enabled) with nice formatting; returns a new response (since reading
  an InputStream body is destructive)."
