[hunchentoot-devel] [hunchentoot] wrong character set in parsing request (#1)

John DeSoi desoi at pgedit.com
Mon Oct 31 12:50:22 UTC 2011


Since this issue has been closed on github, I'd like to repost to the list and get some feedback. It still seems like a bug to me.


> An incoming request has
> 
> Content-Type: application/json; charset=UTF-8
> 
> but the server treats it as latin-1 (the default). It seems the code correctly parses the character set from the content type, but ignores it unless the type is "text". See parse-content-type.


On Oct 30, 2011, at 4:29 PM, Hans Hübner wrote:

> application/json is always encoded as utf-8, at least that is what I understood so far.
> 


So in order to correctly handle a application/json request, I have to explicitly control the request parsing, even though the request has already specified it is UTF-8.

(defhandler (rpc-handler :uri "/rpc" :default-request-type :post) ()
  (setf (tbnl:content-type*) "application/json")
  (setf (tbnl:reply-external-format*) +utf-8+)
  (invoke-rpc (tbnl:raw-post-data :external-format +utf-8+)))


The parse-content-type function parses the "charset" part, but then completely ignores it if the mime type does not have "text" in it. If the content type had been "text/json", it would have worked correctly. 




John DeSoi, Ph.D.








More information about the Tbnl-devel mailing list