Fork me on GitHub
#pedestal
<
2018-07-17
>
jose10:07:21

I have one route where I want to skip the secure-headers default interceptor, but for all the others, I want to use the default interceptors. is it possible for an interceptor to remove another interceptor from the execution queue? (or in this case, just the :leave function)

michael zhou14:07:09

Hi all, what might cause the error?

michael zhou14:07:14

clojure.lang.ExceptionInfo: java.lang.ClassCastException in Interceptor :io.pedestal.http.secure-headers/secure-headers - java.lang.Integer cannot be cast to clojure.lang.Associative at clojure.core$ex_info.invokeStatic(core.clj:4739) at clojure.core$ex_info.invoke(core.clj:4739) at io.pedestal.interceptor.chain$throwable__GT_ex_info.invokeStatic(chain.clj:35) at io.pedestal.interceptor.chain$throwable__GT_ex_info.invoke(chain.clj:32) at io.pedestal.interceptor.chain$try_f.invokeStatic(chain.clj:57) at io.pedestal.interceptor.chain$try_f.invoke(chain.clj:44) at io.pedestal.interceptor.chain$leave_all_with_binding.invokeStatic(chain.clj:254) at io.pedestal.interceptor.chain$leave_all_with_binding.invoke(chain.clj:237) at io.pedestal.interceptor.chain$leave_all$fn__10637.invoke(chain.clj:268) at clojure.lang.AFn.applyToHelper(AFn.java:152) at clojure.lang.AFn.applyTo(AFn.java:144)

Joe Lane14:07:56

@jm301 If you just need uni-directional data flow from server => client and can settle for http posts on client => server then the SSE work done with pedestal is REALLY high quality. It even lets you pick up where you left off if you’re streaming ordered data by providing an identifier for the last payload you received.

Joe Lane14:07:27

@zhoumin79 Looks like you’re using an integer somewhere that secure-headers is expecting a hashmap

michael zhou14:07:23

(def csp-header (sec-headers/content-security-policy-header {:default-src “‘self’” :font-src “‘self’ https://at.alicdn.com” :connect-src “‘self’ <ws://localhost:3449/>” :style-src “‘self’ ‘unsafe-inline’” :object-src “‘none’” :script-src “‘self’ ‘unsafe-inline’ ‘unsafe-eval’ https: http:“})) ;; Consumed by xlight.server/create-server ;; See http/default-interceptors for additional options you can configure (def service {:env :prod ::http/routes routes ::http/type :jetty ::http/port 8080 ::http/resource-path “/public” ;::http/allowed-origins {:creds true :allowed-origins (constantly true)} ;::http/allowed-origins [“*”] ;; Content Security Policy (CSP) is mostly turned off in dev mode ::http/secure-headers {:content-security-policy-settings csp-header} ::http/container-options {:h2c? true :h2? false :read-only? false ;:keystore “test/hp/keystore.jks” ;:key-password “password” ;:ssl-port 8443 :ssl? false} })

michael zhou14:07:57

@joe.lane my secure-headers config, when I delete an item,it triggers this error. Wrong config?

michael zhou14:07:20

(reg-event-fx :delete-user (fn [ [ user-id]] {:http {:method DELETE :url (str “/users/” (clj->js user-id)) :ignore-response-body true :success-event [:navigate-to-home-page]}}))

michael zhou14:07:40

The user deleted.But it shows the above error and this

michael zhou14:07:42

INFO i.p.http.impl.servlet-interceptor - {:msg “sending error”, :message “Internal server error: exception”, :line 215}

michael zhou14:07:37

;(db/delete-user {:userid 778}) (defn delete-user [request] (let [id (get-in request [:path-params :id])] (db/delete-user {:userid (Integer/parseInt id)})))

michael zhou14:07:35

Do anyone have a clue? Thanks.

Joe Lane14:07:17

Which version of pedestal are you running?

michael zhou14:07:43

[io.pedestal/pedestal.service “0.5.4”] [io.pedestal/pedestal.jetty “0.5.4"]

Joe Lane14:07:29

Are you running the dev server or in production mode?

michael zhou14:07:28

lein run--- prod mode

Joe Lane14:07:23

The result from your delete-user function is likely the number of rows affected as a count correct? The result from delete-user must be a map.

Joe Lane14:07:51

Its getting mad because the csp leave handler happens to be trying to call functions on the result of delete-user, which is an integer.

Joe Lane14:07:30

delete-user in this scenario is a handler

Joe Lane14:07:36

in pedestal terminology

Joe Lane14:07:49

So I looked at a sample project

Joe Lane14:07:14

the result of delete-user needs to be a response object, like from the ring project

Joe Lane14:07:01

You’ve almost got it, you just need to return the right thing from delete-user

michael zhou15:07:00

@joe.lane thank you very much. I see.

michael zhou15:07:02

(http/json-response (db/delete-user {:userid id}))

Joe Lane15:07:05

Did that end up workin for you @zhoumin79?