martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
405 stars 23 forks source link

Make it possible to configure the content type of responses returned by generic handlers involving templates #145

Closed ellmetha closed 3 months ago

ellmetha commented 7 months ago

Description

Generic handlers that make use of the Marten::Handlers::Rendering to render templates (like the Marten::Handlers::Template generic handler for example), should make it possible to easily configure the content type associated with the generated response containing the rendered template. By default, this content type should be text/html but it should be possible to override this by calling a dedicated class method.

The envisioned API is as follows:

class MyHandler < Marten::Handlers::Template
  template_name "app/test.xml"
  content_type "application/xml"
end

Special care should be taken to ensure that this class method is added at the Marten::Handlers::Rendering concern level in order to ensure that all generic handlers including it also benefit from this capability.