Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## [Unreleased]

## [1.26.1] - 2026-07-17

### Fixed

- Correctly check content type for custom renderers (#357).

## [1.26.0] - 2026-07-07

### Added
Expand Down
4 changes: 2 additions & 2 deletions lib/rage/controller/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def prepare_action_params(action_name = nil, **opts, &block)
end
end # class << self

DEFAULT_CONTENT_TYPE = "application/json; charset=utf-8"
DEFAULT_CONTENT_TYPE = "application/json; charset=utf-8".dup
private_constant :DEFAULT_CONTENT_TYPE

# @private
Expand Down Expand Up @@ -492,7 +492,7 @@ def render(json: nil, plain: nil, sse: nil, status: nil)
json.is_a?(String) ? json : json.to_json
else
ct = @__headers["content-type"]
@__headers["content-type"] = "text/plain; charset=utf-8" if ct.nil? || ct == DEFAULT_CONTENT_TYPE
@__headers["content-type"] = "text/plain; charset=utf-8" if ct.nil? || ct.equal?(DEFAULT_CONTENT_TYPE)
plain.to_s
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rage/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Rage
VERSION = "1.26.0"
VERSION = "1.26.1"
end
19 changes: 19 additions & 0 deletions spec/configuration/custom_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,24 @@ def build_controller(&block)
[202, { "content-type" => "application/json; charset=utf-8" }, ["{\"message\":\"test\"}"]]
)
end

it "doesn't overwrite default content type for renderers with implicit render" do
config.renderer(:jsonld) do |data|
headers["content-type"] = "application/json; charset=utf-8"
data.merge(:@context => "https://schema.org").to_json
end

config.__finalize

controller = build_controller do
define_method(:index) do
render jsonld: { name: "Alice" }
end
end

expect(run_action(controller, :index)).to match(
[200, { "content-type" => "application/json; charset=utf-8" }, [include("Alice")]]
)
end
end
end