Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 307
prismofeverything Avatar asked Nov 30 '12 04:11

prismofeverything


1 Answers

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

like image 120
cemerick Avatar answered Nov 15 '22 05:11

cemerick