Fork me on GitHub
#ring
<
2017-01-18
>
sova-soars-the-sora01:01:31

@seancornfield I have my application startup using a ring plugin with a ring handler provided in project.clj ...

sova-soars-the-sora01:01:26

but I think now I'm just going to take the sente base application (that works with sockets and httpkit) and just superimpose my application-thus-far onto it. easier than trying to reason about layers of web intestine imho

seancorfield01:01:07

That would be my recommendation. I’ve always avoided the plugins as being too much “magic” — so I can control my web app startup / shutdown directly myself.

seancorfield01:01:21

Makes it easier to switch build tools too 🙂

sova-soars-the-sora03:01:21

Okay new qustion, (file-response) causes Opera to download the file (html file) instead of rendering it.. Content-Type being funky?

seancorfield03:01:31

@sova Possibly. If you're on a unix-y system you can use curl -I to see what HTTP headers you get back from that request.

seancorfield03:01:22

That would tell you whether Content-Type is being set or not. I'd have to look at the source (of Ring) to know whether (file-response ...) sets that header.

seancorfield04:01:27

OK, @sova no, ring.util.response/file-response does not set Content-Type so you need to explicitly set that yourself: https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/util/response.clj#L136-L148

seancorfield04:01:37

(-> (resp/file-response ...) (resp/content-type "text/html")) or you could use the content-type middleware (which will automatically set the Content-Type header based on the file extension in the URL, if no Content-Type is already set).

seancorfield04:01:33

To be honest, I'd recommend using ring-defaults to set up your middleware so you don't have to worry about this much. That automatically adds the content type middleware and a bunch of other useful stuff...

sova-soars-the-sora05:01:07

@seancorfield ah thank you so much. what i'm using already has wrap-defaults and wrap-params but they are not doing the content-type setting, which is interesting...

seancorfield05:01:03

What is your URI for the request? The content type middleware assumes the URI ends in .something and uses that something to look up a content type.

seancorfield05:01:31

So your URI would need to end in .htm or .html to automatically set Content-Type to "text/html".

sova-soars-the-sora05:01:16

Oh. Yeah I suppose I'll have to set it manually then. I was just working with

(defroutes 
  (GET "/" [] (index)))

seancorfield05:01:33

Yup, if you're serving files that don't match any presumed "extension" in the URI, you'll need to set the content type yourself (I've run into this several times before -- (resp/response "Hello!") doesn't set "text/html" or "text/plain" so some browsers will download that response...

sova-soars-the-sora05:01:22

Yeah the download is kinda funny. I dig why it happens but I think every page I want to serve is "text/html"

sova-soars-the-sora05:01:48

I guess I can just use the normal ring response map and manually have a :headers field

seancorfield05:01:22

I tend to have a html function in my Ring apps like this: (defn html [body] (-> (resp/response body) (resp/content-type "text/html")))

seancorfield05:01:40

(from memory -- I'm not at my main computer right now)

sova-soars-the-sora05:01:05

Ah okay. Things are working. Awesome 🙂

sova-soars-the-sora05:01:10

Thanks a lot for your help @seancorfield