ring-clojure / ring-clojure/ring

Feature: Configurable content type handling in wrap-stacktrace-web middleware

Open
#121 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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.

  1. Changing ex-response to a multimethod that dispatches by matching regular expressions against the accept header. This lets users add additional content types and lets them customize the responses themselves.
  2. Adding a configuration option to wrap-stacktrace-web that specifies the content type to use for determining whether to respond with JSON. This wouldn't let you configure additional content types.
  3. Changing the regular expression ex-response to also accept application/json and 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.