sunng87 / ring-jetty9-adapter

An enhanced version of jetty adapter for ring, with additional features like websockets, http/2 and http/3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

run-jetty doesn't accept vars as handlers

hiredman opened this issue · comments

using with-meta like this https://github.com/sunng87/ring-jetty9-adapter/blob/master/src/ring/adapter/jetty9/handlers/sync.clj#L19 to attach metadata to a handler the definition of a handler from any functions (something that implements IFn) to functions that you can use with-meta with (implements IObj and IFn).

Vars don't implement IObj but do implement IFn, and it has been a common idiom to use a var as a ring handler to allow re-definition of the handler at the repl.

Additionally using with-meta to add metadata to a function essential wraps the function in something like (fn [ & args] (apply f args)) with the varargs performance hit (which is admittedly small and may get swamped by io overheads in a webserver)

Sounds reasonable. I will find time to resolve this. If you are interested in a PR for this, it's welcomed

@hiredman is right (WRT a potential performance concern) - see here.

In my very first attempt when coding this up, I was passing a vector of two elements as the -state, and was simply destructuring that inside -doHandle. The only reason I switched to metadata was because I thought it would be faster. However, on second thought, that was a mistake, and is precisely what complicates things with PR #103 .