curl -vvv -H "Accept: text/html;charset=UTF-8" <YOUR_URL>
Assuming the response is html. That will tell you what encoding Spray
is returning in the header. I haven't tried different encoding but so
far Spray has honored the accept header for different content types.
Chris
the `Accept` header does not define a `charset` parameter for a media type. The latter is used with the `Content-Type` header (which also contains a media type but describes the content of the current message not the requirements for a response).
What you are looking for is the `Accept-Charset` header:
curl -vvv -H "Accept-Charset: utf-8" MyUrl > tmpFile
spray honors the client requirements here (even though quality values are not yet supported).
Cheers,
Mathias
---
mat...@spray.cc
http://www.spray.cc
the HTTP spec states: "If no Accept-Charset header is present, the default is that any character set is acceptable."
Since the default charset for HTTP is ISO-8859-1 spray resorts to ISO-8859-1 if the client does not request something else.
Of course you can still produce a response using UTF-8, e.g. via one of the following ways:
- Respond with an explicit HttpContent:
ctx.complete(HttpContent(ContentType(`text/plain`, `UTF-8`), "Anaïs et le garçon"))
- Transform the inner response:
respondWithCharset(`UTF-8`) {
completeWith("Anaïs et le garçon")
}
def respondWithCharset(charset: HttpCharset) = transformResponse {
_.withContentTransformed { content =>
HttpContent(ContentType(`text/plain`, charset), content.as[String].right.get)
}
}
- Use a custom StringMarshaller
HTH and cheers,
Mathias
---
mat...@spray.cc
http://www.spray.cc