Permalink
Browse files

Set response encoding according to 'charset' field of 'Content-Type'

header or to UTF-8 by default
  • Loading branch information...
1 parent 8dc40e8 commit 0ef8aaf4689f88e21ce4b74dcf9f360097b97d7f @dancingrobot84 dancingrobot84 committed with weavejester Jun 12, 2011
Showing with 3 additions and 0 deletions.
  1. +3 −0 ring-servlet/src/ring/util/servlet.clj
View
3 ring-servlet/src/ring/util/servlet.clj
@@ -70,6 +70,9 @@
(.addHeader response key val))))
; Some headers must be set through specific methods
(when-let [content-type (get headers "Content-Type")]
+ ; Parse charset and set response encoding from it or set UTF-8 by default
+ (let [encoding (or (second (re-find #"charset=(.+);?" content-type)) "utf-8")]
+ (.setCharacterEncoding response encoding))
(.setContentType response content-type)))
(defn- set-body

0 comments on commit 0ef8aaf

Please sign in to comment.