-
Notifications
You must be signed in to change notification settings - Fork 51
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
Disabling Muuntaja with Content-Type header is case-sensitive #99
Comments
I believe only request headers are downcased, response headers are sent as-is. |
Yes, so there's no established convention on which case should be used by the application and the middlewares to avoid exactly this situation. |
Hmm. The http spec says it's "Content-Type" and (all?) the clojure libs (ring, pedestal, yada, muuntaja) use this casing as well. I would say it's the convention to use. https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/util/response.clj I wonder if there any fast ways to do ignore-case lookup on pers.maps? |
I don't know if there's a fast way. I suppose that ultimately this is a bug in the Ring spec, since it does not specify how to handle response headers in an interoperable way, but probably it's too late to change it now. |
I recall James thinked aloud about Ring Spec2, with namespaces keys. So, maybe there is a chance to get something for this too? I would like to see Ring Requests and Responses as protocols myself.... |
I guess Ring's answer to this problem right now is that you should use |
Hi, working on that. Just to let you know. I'll prepare a PR as soon as I'm done. You might want to check out my fork in the meanwhile. |
I'm using muuntaja with babashka/http-client and have run into this same problem with a server that returns "content-type" (lower-case). (I'm considering hato, but am nervous about the lack of activity on that repo) This is an awesome library and it's ability to work consistently for clients and servers, for requests and responses is refreshing. Thank you. FWIW, I think the "safe" way to handle headers is something very much like the ring code referenced above. Another option would be to normalize the headers before processing using |
This issue came up in slack
So as it stands, there is a footgun with muuntaja, you have to use lowercased response headers. Since Ring 1.x will not change on this matter and Ring 2.x isn't coming anttime soon (see last link above), maybe the solution is to:
OR
|
Muuntaja does not encode the response if a
Content-Type
header has been set. Header names are case-insensitive but Muuntaja's check is case-sensitive, so if you set the headercontent-type
, it won't disable the encoding.Considering that the Ring spec says that the request headers will be downcased, I'd expect downcased headers to work in the response maps as well.
The text was updated successfully, but these errors were encountered: