Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-conditions to reject invalid URL inputs #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mjul
Copy link
Contributor

@mjul mjul commented Oct 6, 2022

Add pre-conditions to check inputs when creating responses, ensuring that URLs look like URLs.

This improves the developer experience by giving a clear error message rather than an obscure stack trace from the underlying web server infrastructure.

Without this, if you accidentally wrote (created {:message "OK}) the framework would assume that the map is a URL and at a later point explode with a stack-trace like the one below.

With this change, it would give you a specific error in the call to created.

ERROR request UT005071: Undertow request failed HttpServerExchange{ POST /api/events/upload}
 java.lang.ClassCastException: class clojure.lang.PersistentArrayMap cannot be cast to class java.util.Collection (clojure.lang.PersistentArrayMap is in unnamed module of loader 'app'; java.util.Collection is in module java.base of loader 'bootstrap')
        at shadow.undertow.impl$set_headers$fn__19303.invoke(impl.clj:62)
        at clojure.lang.PersistentArrayMap.kvreduce(PersistentArrayMap.java:429)
        at clojure.core$fn__8525.invokeStatic(core.clj:6908)
        at clojure.core$fn__8525.invoke(core.clj:6888)
        at clojure.core.protocols$fn__8257$G__8252__8266.invoke(protocols.clj:175)
        at clojure.core$reduce_kv.invokeStatic(core.clj:6919)
        at clojure.core$reduce_kv.invoke(core.clj:6910)
        at shadow.undertow.impl$set_headers.invokeStatic(impl.clj:58)
        at shadow.undertow.impl$set_headers.invoke(impl.clj:56)
        at shadow.undertow.impl$ring__GT_exchange.invokeStatic(impl.clj:105)
        at shadow.undertow.impl$ring__GT_exchange.invoke(impl.clj:101)
        at shadow.undertow$eval19556$fn$reify__19563.handleRequest(undertow.clj:406)
        at io.undertow.server.handlers.BlockingHandler.handleRequest(BlockingHandler.java:56)
        at shadow.undertow.ShadowResourceHandler$1.handleRequest(ShadowResourceHandler.java:175)
        at shadow.undertow.ShadowResourceHandler.serveResource(ShadowResourceHandler.java:306)
        at shadow.undertow.ShadowResourceHandler.handleRequest(ShadowResourceHandler.java:139)
        at shadow.undertow.ShadowResourceHandler$1.handleRequest(ShadowResourceHandler.java:175)
        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
        at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1449)
        at java.base/java.lang.Thread.run(Thread.java:829)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant