diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a2232d8..a33dfb53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rage/controller/api.rb b/lib/rage/controller/api.rb index 9ddb9491..55921fff 100644 --- a/lib/rage/controller/api.rb +++ b/lib/rage/controller/api.rb @@ -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 @@ -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 diff --git a/lib/rage/version.rb b/lib/rage/version.rb index 618d59bd..9d4f28b3 100644 --- a/lib/rage/version.rb +++ b/lib/rage/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Rage - VERSION = "1.26.0" + VERSION = "1.26.1" end diff --git a/spec/configuration/custom_renderer_spec.rb b/spec/configuration/custom_renderer_spec.rb index ed57db4a..1bc3f488 100644 --- a/spec/configuration/custom_renderer_spec.rb +++ b/spec/configuration/custom_renderer_spec.rb @@ -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