4

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

Alexander Kondaurov
  • 3,677
  • 5
  • 42
  • 64
  • What are the response headers in spray? and what version of akka-http you're using? Here are the discussions on this topic https://github.com/akka/akka/issues/17409 https://github.com/akka/akka/issues/19260 – maks Oct 11 '16 at 01:08
  • I use akka http 2.4.11. response header in spray has 'charset: utf-8' that's why it works there... I saw that topics but i didn't understand why they are closed and what is the solution. As i understood it's browser bug because application/json has utf-8 by default, but i don't get it why i can't specify 'charset: utf-8' explicitly. – Alexander Kondaurov Oct 11 '16 at 08:22

2 Answers2

5

I found method withParams. Now it works

HttpEntity(ContentType(MediaTypes.`application/json`.withParams(Map("charset" -> "utf-8"))), "Привет".getBytes("UTF-8"))
Alexander Kondaurov
  • 3,677
  • 5
  • 42
  • 64
5

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.

jrudolph
  • 8,307
  • 4
  • 32
  • 50