ring icon indicating copy to clipboard operation
ring copied to clipboard

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

Open achin opened this issue 11 years ago • 0 comments

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?

achin avatar Jan 31 '14 15:01 achin