Fork me on GitHub

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


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


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.


Makes it easier to switch build tools too 🙂


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


@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.


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.


OK, @sova no, ring.util.response/file-response does not set Content-Type so you need to explicitly set that yourself:


(-> (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).


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...


@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...


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.


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


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

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


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...


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


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


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


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


Ah okay. Things are working. Awesome 🙂


Thanks a lot for your help @seancorfield