Search code examples
utf-8clojurering

clojure and ring: utf-8 in responses comes through as '?'


I was surprised to find my ring app was not serving utf-8 properly. I pared this down to a simple test case, does anyone know how to ensure that this will always return utf-8 to the browser?

(ns utf8test.core)

(defn app
  [request]
  {:status 200 :body "ɮѪϴ"}) 

In project.clj (using the lein-ring plugin):

:ring {:handler utf8test.core/app} 

In terminal:

> lein ring server

---> ɮѪϴ (this is wrong, should be ɮѪϴ)

Preferably a method that works for tomcat as well, since this is where the app is being deployed.

Thanks!


Solution

  • Without setting a Content-Type header, Jetty is probably sending a response indicating the platform-default encoding. Try using the content-type or charset response functions to add an appropriate header (e.g. (charset {:status 200 :body "..."} "UTF-8")).