Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
72c4737
Sort MIME types alphabetically
timriley Oct 10, 2025
2bc9f4f
Fix documentation typo
timriley Oct 10, 2025
13fb00c
Remove out-of-date setting name from docs
timriley Oct 10, 2025
c6d53d0
Wrap comment at 100 chars
timriley Oct 10, 2025
69fd436
Add clearer and more flexible format config API
timriley Oct 10, 2025
7d82eac
Update tests to use new formats config API
timriley Oct 11, 2025
7a9484e
Add deprecation notices
timriley Oct 11, 2025
be1aa73
Expand unit specs for formats
timriley Oct 11, 2025
b23411b
Add a final deprecation warning
timriley Oct 11, 2025
b84b800
Update mapping= to uew new register method
timriley Oct 12, 2025
d7127e8
Register formats with explicit media and content types
timriley Oct 16, 2025
f632ce7
Drop Ruby 3.1 support
timriley Oct 16, 2025
07126ad
wip passing
timriley Oct 17, 2025
c950b9c
fix var name in initialize_copy
timriley Oct 17, 2025
f297908
Stricter response type setting when we can
timriley Oct 17, 2025
f639cfc
Shift the patched best_q_match to bottom of public methods
timriley Oct 17, 2025
d26f11b
Reorder methods so they’re sensible to me
timriley Oct 17, 2025
d5b19b5
Update enforce_accept for multiple accept types
timriley Oct 17, 2025
7d6df43
Tidy methods supporting enforce_content_type
timriley Oct 17, 2025
1643426
Tidy remaining media_type methods
timriley Oct 17, 2025
364be3a
Fix a couple of old-style format configs
timriley Oct 17, 2025
edad4f8
Get formats unit spec passing again
timriley Oct 17, 2025
cb5032f
Update docs
timriley Oct 17, 2025
61f4a78
Remove stale TODO
timriley Oct 17, 2025
73e499a
Add missing private_constant
timriley Oct 17, 2025
0535c43
Add test for restrictive content type setting
timriley Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
- "3.4"
- "3.3"
- "3.2"
- "3.1"
rack:
- "~> 2.0"
- "~> 3.0"
Expand Down
15 changes: 12 additions & 3 deletions lib/hanami/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ def self.prepend_after(...)
# @since 2.0.0
# @api public
def self.format(...)
msg = <<~TEXT
Hanami::Action `format` is deprecated and will be removed in Hanami 2.4.

Please use `config.formats.accept` instead.

See https://guides.hanamirb.org/v2.3/actions/formats-and-mime-types/ for details.
TEXT
warn(msg, category: :deprecated)

config.format(...)
end

Expand Down Expand Up @@ -326,7 +335,7 @@ def call(env)
session_enabled: session_enabled?
)

enforce_accepted_mime_types(request)
enforce_accepted_media_types(request)

_run_before_callbacks(request, response)
handle(request, response)
Expand Down Expand Up @@ -413,7 +422,7 @@ def _requires_no_body?(res)

# @since 2.0.0
# @api private
def enforce_accepted_mime_types(request)
def enforce_accepted_media_types(request)
return if config.formats.empty?

Mime.enforce_accept(request, config) { return halt 406 }
Expand Down Expand Up @@ -596,7 +605,7 @@ def finish(req, res, halted)
_empty_headers(res) if _requires_empty_headers?(res)
_empty_body(res) if res.head?

res.set_format(Action::Mime.detect_format(res.content_type, config))
res.set_format(Mime.format_from_media_type(res.content_type, config))
res[:params] = req.params
res[:format] = res.format
res
Expand Down
13 changes: 12 additions & 1 deletion lib/hanami/action/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def handle_exception(exceptions)

# Sets the format (or formats) for the action.
#
# To configure custom formats and MIME type mappings, call {Formats#add formats.add} first.
# To configure custom formats and MIME type mappings, call {Formats#register formats.register}
# first.
#
# @example
# config.format :html, :json
Expand All @@ -82,10 +83,20 @@ def handle_exception(exceptions)
# @since 2.0.0
# @api public
def format(*formats)
msg = <<~TEXT
Hanami::Action `config.format` is deprecated and will be removed in Hanami 2.4.

Please use `config.formats.register` and/or `config.formats.accept` instead.

See https://guides.hanamirb.org/v2.3/actions/formats-and-mime-types/ for details.
TEXT
warn(msg, category: :deprecated)

if formats.empty?
self.formats.values
else
self.formats.values = formats
self.formats.default = formats.first
end
end

Expand Down
Loading