File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 8787 (-> (ok " true" )
8888 (header mw* (str (get-in request [:headers mw*]) 7 ))))
8989
90+ (defn middleware-x
91+ " If request has query-param x, presume it's a integer and multiply it by two
92+ before passing request to next handler."
93+ [handler]
94+ (fn [req]
95+ (handler (update-in req [:query-params " x" ] #(* (Integer. %) 2 )))))
96+
9097; ;
9198; ; Facts
9299; ;
141148 status => 200
142149 body => {:value " third" })))
143150
151+ (facts " middlewares - editing request"
152+ (defapi api
153+ (swaggered +name+
154+ (GET* " /first" []
155+ :query-params [x :- Long]
156+ :middlewares [middleware-x]
157+ (ok {:value x}))))
158+ (fact " middleware edits the parameter before route body"
159+ (let [[status body headers] (get* api " /first?x=5" {})]
160+ status => 200
161+ body => {:value 10 })))
162+
144163(fact " :body, :query and :return"
145164 (defapi api
146165 (swaggered +name+
You can’t perform that action at this time.
0 commit comments