-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AkkaHttp backend modifies content-type header "application/json" with encoding #1449
Comments
Hi, I am not sure if it is even a bug as here https://www.iana.org/assignments/media-types/application/json you can read that there is no charset parameter defined for |
Hi! Yes, you're absolutely right, this is something where akka-http "knows better" and yes, I do agree that the standard you mentioned does define "application/json" without an encoding parameter. It would be a nice world if standards were obeyed :D There are other RFCs and standards, less general that state that content-type header can contain encoding part, such as https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type and https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.5 . Unfortunately some libraries/frameworks implement less specific approach and in this case it would be good to satisfy their requirements even when these are not 100% standard-conform. In other words, the library should not "know better". For example, currently I must communicate with an API that supports few content-types and a lot of functionality is linked to the With akka-http directly it is not strait-forward but possible like val contentType: ContentType.WithFixedCharset = MediaTypes.`application/json`.withParams(Map("charset" -> charset)).toContentType
request.withEntity(request.entity.withContentType(contentType)) So maybe it would make sense to be explicit and apply |
@slavaschmidt unfortunately in the current design we are not able to reliably distinguish between an explicitly-set content type, and a default one coming from a body, as I agree this is a shortcoming of sttp but I think this can only be fixed by breaking binary compatibility (so will have to wait until sttp-client4) |
Related discussion: akka/akka-http#1482 |
Hey @sirthias , thank you for jumping into the discussion. As I mentioned above, the akka-http approach is strict and it is understandable that framework developers strive for purity in regard to the standard. Still, there are few things worth mentioning:
|
It looks like AkkaHttp backend removes charset part of the content-type if the content type is "application/json".
Please compare:
basicRequest.contentType(MediaType.ApplicationJson.charset("UTF-8"))
produces
Custom content type
basicRequest.contentType("application/test", "utf-8")
produces expected result:
I can imagine that the motivation for removing the charset in the first case is because this is the default but in some cases it is crucial to be as specific as possible, for example because of specific server-side requirements.
The text was updated successfully, but these errors were encountered: