luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.59k stars 156 forks source link

Allow setting more custom content types. #1719

Closed jwoertink closed 2 years ago

jwoertink commented 2 years ago

Purpose

Fixes #1580

Description

This opens up a new escape hatch for setting the content type header on different responses like json, xml or plain_text. This also creates a new method that can be overridden at the individual action or base action to globally set your content type for each different response type you use. You always have the option to get real custom with send_text_response that requires setting your own custom content type.

I didn't add an argument to html or component due to the named args that those take in. This would end up causing some conflicts similar to how the status worked for html.

I went with the method option here so you could have this set more globally scoped than if we did a block wrapper or functional style.

class BrowserAction < Lucky::Action

  def html_content_type
    "your_custom_html_content_type"
  end
end

That issue also specified the server response status, but I figure since you can already set that, we may as well just leave that as is for now. This way at least gives us additional escape hatches to push towards 1.0

Checklist