Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.
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

@ccann

Description

@ccann

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions