Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

akka http, charset header, utf-8 issue

I have this route:

path("rus") {
  complete("Привет!")
}

When i go /rus with browser (chrome) i get this output:

"Привет!"

Why? Response headers are:

HTTP/1.1 200 OK
Server: akka-http/2.4.10
Date: Mon, 10 Oct 2016 22:31:53 GMT
Content-Type: application/json
Content-Length: 15

I used to use spray but now i want akka http, i didn't face an issue like this one.

When i curl this path i get normal output

$ curl http://localhost:9010/rus
"Привет!"

I see that response header 'Content-Type' shoud be 'application/json;charset=utf-8' but charset is missing...

like image 901
Alexander Kondaurov Avatar asked Dec 24 '22 00:12

Alexander Kondaurov


2 Answers

I found method withParams. Now it works

HttpEntity(ContentType(MediaTypes.`application/json`.withParams(Map("charset" -> "utf-8"))), "Привет".getBytes("UTF-8"))
like image 109
Alexander Kondaurov Avatar answered Dec 31 '22 12:12

Alexander Kondaurov


Unfortunately, this is a bug in chromium. The charset parameter must be ignored for the application/json content-type according to its IANA registration:

Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients.

like image 27
jrudolph Avatar answered Dec 31 '22 12:12

jrudolph