On 26 November 2014 at 23:08, <ro...@unbounce.com> wrote: > map->CorsPolicy enforces correctness of input, this way the wrap-cors > functions doesn't need to validate data. Probably we can add a call to > map->CorsPolicy as the first thing of wrap-cors function and keep this > function private. >
In Clojure, types and validation are orthogonal concepts. You don't need to use deftype in order to validate a map. For instance, you could write your middleware function instead as: (defn wrap-cors [handler options] (s/validate cors-schema options) (fn [request] ...)) Or better yet, perhaps just use s/defn instead. Given that we are returning a Policy per request call, calling a > map->CorsPolicy every time we call warp-cors sounds a bit overkill > performance wise... Instead of validating development settings once when > the namespaces is loaded, it is being validated every time a request comes > in. > Even though the function wrap-cors returns will be evaluated many times, the wrap-cors function itself will likely only be evaluated once when your handler is created. For instance: (def handler (wrap-cors my-routes cors-options)) This means that there's no performance benefit to creating a type to just contain the option map, particularly since you're not using type hints, so you're accessing the type via reflection. By convention, Ring middleware also takes the handler as the first argument, allowing it to be more easily threaded. - James -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.