ring-clojure / ring-clojure/ring
Feature: Configurable content type handling in wrap-stacktrace-web middleware
Nobody has claimed this yet.
- Dominant language
- Clojure
- Stars
- 3.9k
- Forks
- 528
- PR merge metrics
- No merged PRs in 30d
Description
Right now, the ring.middleware.stacktrace/wrap-stacktrace-web middleware serves either HTML or JSON depending on the request's accept header. If the request accepts text/javascript, then it serves the stacktrace as JSON; otherwise, it serves it as HTML.
I'd like to be able to configure this behavior. For example, I'd like to be able to serve JSON when the request accepts application/json (in addition to text/javascript) and set the response content type correspondingly. I could also envision being able to configure additional content types as well (e.g. XML, text, EDN).
I'm happy to add this feature myself, but I wanted to know how you'd like to approach it. Here are a few ideas I had.
- Changing
ex-responseto a multimethod that dispatches by matching regular expressions against theacceptheader. This lets users add additional content types and lets them customize the responses themselves. - Adding a configuration option to
wrap-stacktrace-webthat specifies the content type to use for determining whether to respond with JSON. This wouldn't let you configure additional content types. - Changing the regular expression
ex-responseto also acceptapplication/jsonand setting the response content type to whichever one was matched. This wouldn't let you add more content types either.
I prefer the multimethod approach, but multimethods aren't really used anywhere else in the code base. What do you think of the idea and which approach would you go with?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the wrap-stacktrace-web middleware and its ex-response handling described in the issue. Compare the three proposed approaches, then trace how the Accept header currently selects HTML or JSON and how the response content type is set. Done means configurable content-type handling, including application/json, with matching responses and coverage for the supported choices.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100