pedestal

2020-04-02T15:21:38.012600Z

Is there anything in the basic pedestal template that would cause it not to be accessible on a remote server but working locally through curl on the same server? Trying to figure out what I'm doing wrong. The correct port seems to be open (and does work from curl)

orestis 2020-04-02T15:27:02.013900Z

The interface by default is localhost, need to change it to bind to 0.0.0.0 instead.

orestis 2020-04-02T15:27:14.014400Z

On mobile so can’t remember how it works

orestis 2020-04-02T15:27:44.015100Z

Was a recent change AFAIK because it’s a security concern

2020-04-02T15:28:20.015300Z

Is it that ::http/allowed-origins must be set?

2020-04-02T15:32:49.015500Z

I tried setting both these keys, as in the dev server

;; all origins are allowed in dev mode
            ::http/allowed-origins {:creds true :allowed-origins (constantly true)}
            ;; Content Security Policy (CSP) is mostly turned off in dev mode
            ::http/secure-headers  {:content-security-policy-settings {:object-src "'none'"}}

2020-04-02T15:47:27.015700Z

Also tried ::http/host "0.0.0.0" as well as the actual IP address

haywood 2020-04-02T20:47:18.016400Z

I’m just trying to return 401 from an interceptor but the server responds with 500

haywood 2020-04-02T20:47:49.016700Z

the interceptor returns

{:status 401 :body   "Unauthorized"}

haywood 2020-04-02T20:48:13.017100Z

which is somewhere in the :body response, but the main response is 500

haywood 2020-04-02T20:48:17.017300Z

I don’t get it

haywood 2020-04-02T20:59:30.017600Z

"clojure.lang.ExceptionInfo: java.lang.NullPointerException in Interceptor :io.pedestal.http.ring-middlewares/content-type-interceptor - \n\tat io.pedestal.interceptor.chain$throwable__GT_ex_info.invokeStatic(chain.clj:35)\n\tat io.pedestal.interceptor.chain$throwable__GT_ex_info.invoke(chain.clj:32)\n\tat io.pedestal.interceptor.chain$try_f.invokeStatic(chain.clj:57)\n\tat io.pedestal.interceptor.chain$try_f.invoke(chain.clj:44)\n\tat io.pedestal.interceptor.chain$leave_all_with_binding.invokeStatic(chain.clj:254)\n\tat io.pedestal.interceptor.chain$leave_all_with_binding.invoke(chain.clj:237)\n\tat io.pedestal.interceptor.chain$leave_all$fn__7211.invoke(chain.clj:268)\n\tat clojure.lang.AFn.applyToHelper(AFn.java:152)\n\tat clojure.lang.AFn.applyTo(AFn.java:144)\n\tat clojure.core$apply.invokeStatic(core.clj:665)\n\tat clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1973)\n\tat clojure.core$with_bindings_STAR_.doInvoke(core.clj:1973)\n\tat clojure.lang.RestFn.invoke(RestFn.java:425)\n\tat io.pedestal.interceptor.chain$leave_all.invokeStatic(chain.clj:266)\n\tat io.pedestal.interceptor.chain$leave_all.invoke(chain.clj:260)\n\tat io.pedestal.interceptor.chain$execute.invokeStatic(chain.clj:379)\n\tat io.pedestal.interceptor.chain$execute.invoke(chain.clj:352)\n\tat io.pedestal.interceptor.chain$execute.invokeStatic(chain.clj:389)\n\tat io.pedestal.interceptor.chain$execute.invoke(chain.clj:352)\n\tat io.pedestal.http.impl.servlet_interceptor$interceptor_service_fn$fn__10376.invoke(servlet_interceptor.clj:351)\n\tat io.pedestal.http.servlet.FnServlet.service(servlet.clj:28)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:505)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)\n\tat <http://org.eclipse.jetty.io|org.eclipse.jetty.io>.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)\n\tat <http://org.eclipse.jetty.io|org.eclipse.jetty.io>.FillInterest.fillable(FillInterest.java:103)\n\tat <http://org.eclipse.jetty.io|org.eclipse.jetty.io>.ChannelEndPoint$2.run(ChannelEndPoint.java:117)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\n\tat org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)\n\tat java.base/java.lang.Thread.run(Thread.java:834)\nCaused by: java.lang.NullPointerException: null\n"

haywood 2020-04-02T20:59:54.017800Z

error is so unhelpful no?

isak 2020-04-02T21:01:35.018300Z

@haywood try adding :headers {}

isak 2020-04-02T21:02:00.018900Z

if you don't have that in there, it isn't considered a valid response for the purposes of short-circuiting, so the next interceptor will fire

haywood 2020-04-02T21:03:11.019300Z

into the request or the interceptor response

isak 2020-04-02T21:03:22.019500Z

the latter

haywood 2020-04-02T21:03:58.019800Z

ok thank you, one sec trying

haywood 2020-04-02T21:05:59.020Z

same error, not sure where the NPE is coming from.

isak 2020-04-02T21:07:08.021200Z

oh, instead of returning {:status 401 :body "Unauthorized" :headers {}} you should assoc that into [ctx :response] (assoc ctx :response &lt;my response map&gt;)

haywood 2020-04-02T21:08:08.021500Z

ah.

haywood 2020-04-02T21:08:12.021700Z

yea that would make sense

haywood 2020-04-02T21:11:31.022Z

(def basic-auth-interceptor
  (interceptor {:name  ::basic-auth
                :enter (fn [context]
                         (update context :request
                                 (fn [req]
                                   (let [auth-req (basic-authentication-request req basic-auth-fn)]
                                     (if (:basic-authentication auth-req)
                                       auth-req
                                       (assoc context
                                              :request
                                              {:status 401
                                               :headers {}
                                               :body   "Unauthorized"}))))))}))

haywood 2020-04-02T21:11:38.022200Z

no dice… still an NPE

isak 2020-04-02T21:12:16.022500Z

you are updating :request instead of :response

haywood 2020-04-02T21:12:42.022700Z

where do I venmo you money for wasting your time

isak 2020-04-02T21:12:58.022900Z

lol

haywood 2020-04-02T21:36:12.024900Z

just to close this out, had to change my interceptor definition:

(def basic-auth-interceptor
  (interceptor {:name  ::basic-auth
                :enter (fn [context]
                         (let [req      (:request context)
                               auth-req (basic-authentication-request req basic-auth-fn)]
                           (if (:basic-authentication auth-req)
                             (assoc context :request auth-req)
                             (assoc context :response
                                    {:status  401
                                     :headers {}
                                     :body    "Unauthorized"}))))}))

1
haywood 2020-04-02T21:36:24.025200Z

Thank you for opening my eyes to my idiocy