Skip to content

Commit

Permalink
0.9.2 Add :middleware-wrapper-fn option to inject middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Nov 13, 2016
1 parent 4185f82 commit 29ee228
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ as a map (preferred) or as an arbitrary number of inline key / value pairs (lega
* `:home` - the _"section.item"_ pair used for the / URL, defaults to `:default-section` and `:default-item` values.
* `:json-config` - specify formatting information for Cheshire's JSON `generate-string`, used in `render-json` (`:date-format`, `:ex`, `:key-fn`, etc).
* `:middleware-default-fn` - an optional function that will be applied to Ring's site defaults; note that by default we do **not** enable the XSRF Anti-Forgery middleware that is normally part of the site defaults since that requires session scope and client knowledge which is not appropriate for many uses of FW/1. Specify `#(assoc-in % [:security :anti-forgery] true)` here to opt into XSRF Anti-Forgery (you'll probably also want to change the `:session :store` from the in-memory default unless you have just a single server instance).
* `:middleware-wrapper-fn` - an optional function that will be applied as the outermost piece of middleware, wrapping all of Ring's defaults (and the JSON parameters middleware).
* `:options-access-control` - specify what an `OPTIONS` request should return (`:origin`, `:headers`, `:credentials`, `:max-age`).
* `:password` - specify a password for the application reload URL flag, default `"secret"` - see also `:reload`.
* `:reload` - specify an `rc` key for the application reload URL flag, default `:reload` - see also `:password`.
Expand Down
2 changes: 1 addition & 1 deletion resources/fw1.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.1
0.9.2
10 changes: 7 additions & 3 deletions src/framework/one.clj
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,17 @@
(defn- default-middleware
"The default Ring middleware we apply in FW/1. Returns a single
composed piece of middleware. We start with Ring's site defaults
and the fn passed in may modify those defaults."
[modifier-fn]
and the modifier-fn passed in may modify those defaults. Then we
wrapper the handler in one last optional piece of middleware."
[modifier-fn wrapper-fn]
(fn [handler]
(-> handler
(ring-md/wrap-defaults (-> ring-md/site-defaults
; you have to explicitly opt in to this:
(assoc-in [:security :anti-forgery] false)
modifier-fn))
(ring-json/wrap-json-params))))
(ring-json/wrap-json-params)
(wrapper-fn))))

(def ^:private default-options-access-control
{:origin "*"
Expand All @@ -479,6 +481,8 @@
[(:default-section options) (:default-item options)])
; can modify site-defaults
:middleware (default-middleware (or (:middleware-default-fn options)
identity)
(or (:middleware-wrapper-fn options)
identity))
:options-access-control (merge default-options-access-control
(:options-access-control options))))
Expand Down

0 comments on commit 29ee228

Please sign in to comment.