This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-23
Channels
- # arachne (3)
- # aws (1)
- # bangalore-clj (2)
- # beginners (19)
- # boot (151)
- # cider (72)
- # cljs-dev (9)
- # cljsjs (7)
- # cljsrn (37)
- # clojure (215)
- # clojure-austin (1)
- # clojure-denmark (2)
- # clojure-dev (68)
- # clojure-india (1)
- # clojure-ireland (2)
- # clojure-italy (4)
- # clojure-mke (1)
- # clojure-nl (4)
- # clojure-russia (4)
- # clojure-serbia (1)
- # clojure-spec (29)
- # clojure-uk (23)
- # clojurescript (23)
- # cursive (24)
- # datomic (71)
- # emacs (5)
- # events (1)
- # gsoc (11)
- # hoplon (20)
- # klipse (4)
- # lambdaisland (2)
- # leiningen (3)
- # luminus (3)
- # off-topic (30)
- # om (40)
- # om-next (1)
- # onyx (15)
- # pedestal (19)
- # perun (7)
- # planck (23)
- # proton (1)
- # protorepl (2)
- # re-frame (35)
- # reagent (21)
- # ring-swagger (38)
- # rum (19)
- # spacemacs (9)
- # untangled (11)
- # vim (5)
- # yada (4)
hmm, bit of a strange one, using compojure-api resources in front of my liberator resources , in liberator i’m setting CORS headers for all responses (access-control-allow-origin etc) , these are being returned correctly for all request methods except for OPTIONS , where they are not being returned at all
(defn site-resource [db-spec]
(api/resource
{:tags ["sites"]
:description "Sites"
:head {:summary "Return HTTP Headers"
:responses {status/ok nil}}
:options {:summary "Return available HTTP OPTIONS"
:responses {status/ok nil}}
:get {:summary "Return Site records, optionally filtered by URL parameters."
:parameters {:query-params SiteQueryParams}
:responses {status/ok {:schema SiteArrayResponse}}}
:post {:summary "Create a new Site record."
:parameters {:body-params Site}
:responses {status/created {:schema SiteCreated}}}
:handler (site db-spec)}))
doesn’t seem like it should be required to specify these headers in my responses since they are being returned fine for everything other than OPTIONS
thanks, i’m poking around the source trying to follow the execution path but yeh taking a bit to get my head around it 🙂
it is returning an Allow header for OPTIONS that i’m not generating in my liberator resource as well
hmm… the resource
isn’t doing anything extra, just coercion and selecting the right handler.
and actually just stuck a debug log in , on OPTIONS it doesn’t appear to be calling my liberator handler at all
any middleware further up the chain that would be using the keys in my resource definition to generate the Allow header? as that appears to be what’s happening
hmm… sounds like it. compojure-api doesn’t do anything like that, or shoudn’t at least.
((api
(context "/" []
(resource {:handler (fn [_] {:headers "kikka"})})))
{:request-method :options, :uri "/"})
; => {:headers "kikka"}
that’s the minimalstic set: api + context + resource => nothing looking for OPTIONS.
nah i removed all other middleware , just have api-middleware , ring-logger and liberator.dev/wrap-trace
if you replace your liberator handler with something like (constantly {:headers “kikka”})
, does it return it?
only place I found any mark of OPTIONS was the Liberator codebase itself, some rules about it: https://github.com/clojure-liberator/liberator/blob/60ca12f12d1a322202de5659b8ab510d9bcc7884/src/liberator/core.clj
hmm no when i replace my liberator resource with :handler (constantly {:headers “kikka”}) i get a 500 java.lang.UnsupportedOperationException: nth not supported on this type: Character
hmm, actually before i misspke , my handler was getting called , i can see my liberator decision graph , it just wasn’t getting to the response handler which works ok when i wasn’t using compojure-api
strange so :as-response which lets me send back through the raw response , is called when i use the liberatr resource directly , for some reason not being passed back now