Fork me on GitHub
#pedestal
<
2017-05-30
>
bherrmann00:05:21

@mtnygard Thanks, that hit the nail on the head!

bherrmann00:05:57

The mylib.jar is actually oracles jdbc library… which they are a pita about not sharing via maven central… so I have to include out of band instructions for oracle users.

lellis18:05:06

Hi all! Its possible to use Interceptor in websocket route?

mtnygard18:05:15

You can use interceptors directly by calling http://pedestal.io/api/pedestal.interceptor/io.pedestal.interceptor.chain.html#var-execute with a context that you devise.

pedroteixeira22:05:12

hello, is there some way to pass :allow-symlinks? to the interceptor that already serves files from sources ::http/resource-path ?

mtnygard22:05:53

Let me look into that @pedroteixeira.

pedroteixeira22:05:00

thanks, really appreaciated - don't know yet where to look this up in the code

pedroteixeira22:05:02

I'm not sure if I should create a new interceptor for this case

mtnygard22:05:43

The interceptor supports it if you call io.pedestal.http.ring-middlewares/fast-resource directly like this:

(middlewares/fast-resource "public" {:follow-symlinks? true})

mtnygard22:05:53

That will return you the interceptor you want.

mtnygard22:05:04

The second part is to use that instead of the default resource interceptor.

mtnygard22:05:29

So I suggest: 1. Leave ::http/resource as nil in your service map. 2. Construct your own interceptor. 3. Call io.pedestal.http/default-interceptors to construct the default interceptor stack. (This is normally done by create-server) 4. Conj your interceptor into the defaults. 5. Start the server.

mtnygard22:05:51

It'll probably take less than 5 lines of code. 🙂

souenzzo22:05:51

There is a standard way to use Edn on query string?

mtnygard22:05:22

@souenzzo What would be an example of such a query string?

souenzzo12:05:45

mtnygard: I want for example, send and UUID on query string.

mtnygard21:05:05

The parameter will always arrive as a string. But you could run it through clojure.tools.reader.edn/read-string. If you wanted to do this in general, you could write an interceptor that parsed a set of query parameters (provided at construction time).

souenzzo13:06:58

So, "bar"}... Obviously with attention to URL encode I'm unsure if there was some default interceptor already.

souenzzo13:06:07

for path-params. may be a thing? Then I read-string on all values. It sounds like a good idea?

pedroteixeira23:05:59

@mtnygard trying something along the lines, can you shed some light?

(http/create-server 
   (update
     (http/default-interceptors service-map)
      ::http/interceptors
       #(conj % (ring-middlewares/fast-resource "public" {:follow-symlinks? true}))))
 
I got the code from the guide on the side that used defrecord Pedestal

mtnygard23:05:12

Looks reasonable. Is it working?

pedroteixeira23:05:30

I think I got something wrong cause getting exception java.nio.file.StandardOpenOption cannot be cast to [Ljava.nio.file.OpenOption_ for any GET

mtnygard23:05:09

That looks like a bug in the interceptor itself.

pedroteixeira23:05:11

I was looking for examples in ways to conj an interceptor into the default ones

mtnygard23:05:21

Are you using Jetty?

pedroteixeira23:05:42

yes - is it the preferred/easy option?

mtnygard23:05:44

The exception says that someone is passing a single OpenOption where the API requires an array of them.

mtnygard23:05:52

That's not something you did.

mtnygard23:05:12

It's probably a problem in the fast interceptor.

mtnygard23:05:44

I'm at dinner now but can take a look in about an hour.

pedroteixeira23:05:06

is there an easy way to use ring.util.response/resource-response as the interceptor?

pedroteixeira23:05:22

I see on the default interceptors, it is used instead of the fast-response

mtnygard23:05:31

Yes, but it doesn't have the follow-symlinks option.

mtnygard23:05:59

Ah, ok. I can help in a while. Or in the meantime you could copy the function that builds the regular resource interceptor. (Right above fast-resource) and modify it to use the new middleware.

pedroteixeira23:05:11

ok thanks for the help 👍 - I will try copying the resource/resource-request to add the new arg, if there is a better way, let me know

pedroteixeira23:05:02

it worked fine but had to copy to include support for the new arg

(defn resource-request
  "If request matches a static resource, returns it in a response map.
  Otherwise returns nil."
  {:added "1.2"}
  [request root-path & [{:keys [loader]}]]
  (if (#{:head :get} (:request-method request))
    (let [path (subs (codec/url-decode (request/path-info request)) 1)]
      (-> (response/resource-response path {:root root-path :loader loader :allow-symlinks? true})
          (head/head-response request)))))