Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Can't drop charset from media type parameters #63

Open
ccann opened this issue Sep 14, 2016 · 0 comments
Open

Can't drop charset from media type parameters #63

ccann opened this issue Sep 14, 2016 · 0 comments

Comments

@ccann
Copy link

ccann commented Sep 14, 2016

My API has to conform to the JSON API format http://jsonapi.org/format/

I referenced 6f29307 and built a custom encoder with application/vnd.api+json as content type but then the charset media type parameter is added. I tried specifying :charset "" in wrap-restful-response options and got an exception re unsupported charset.

My solution is this janky middleware:

(defn wrap-mime-type
  "Middleware to replace existing json MIME type with JSON-API MIME type,
   dropping charset."
  [handler]
  (fn [request]
    (let [response (handler request)
          headers {"Content-Type" "application/vnd.api+json"}]
      (if (-> response
              (get-in [:headers "Content-Type"])
              (str/includes? "application/json"))
        (update-in response [:headers] merge headers)
        response))))

Is there a way to do this that I missed?

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant