问题
I have created a brand new app from the luminus app template using lein new luminus my-app +postgres +auth +cljs +swagger
. In the generated file src/clj/my_app/routes/home.clj
the following compojure route is created:
(GET "/docs" [] (response/ok (-> "docs/docs.md" io/resource slurp)))
When I try to access localhost:3000/docs
the file is simply downloaded instead of displayed in the browser. It happens both with Chrome and Safari.
It seems related to ring.util.http-response/ok
since I can reproduce the behavior using this route too:
(GET "/hi" [] (response/ok "hi"))
.
A file "hi" is then downloaded with file content "hi".
Any ideas on what's causing this?
回答1:
Your response handler doesn't set Content-Type
for your response body.
You can do it using ring.util.http-response/content-type
:
(GET "/hi" [] (-> "hi"
(response/ok)
(response/content-type "text/plain")))
You can also wrap your handler in ring.middleware.content-type/wrap-content-type so the headers are "guessed" based on the file extension from the URI.
来源:https://stackoverflow.com/questions/35548372/file-is-downloaded-instead-of-being-displayed-in-the-browser