ring
ring copied to clipboard
Feature: Configurable content type handling in wrap-stacktrace-web middleware
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?