From 85c939d33152bb8b56e0b768528b4ea428a75755 Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:18:23 +0100 Subject: [PATCH 1/4] Correctly check content type for custom renderers this fixes a bug where content type is overwritten to `text/plain` if a custom renderer sets the (default) application-json content type using implicit render --- lib/rage/controller/api.rb | 4 ++-- spec/configuration/custom_renderer_spec.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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/spec/configuration/custom_renderer_spec.rb b/spec/configuration/custom_renderer_spec.rb index ed57db4a..64355e6d 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 From ec70b129ab7827f3a4003b9e5a3ad7b5635f8e55 Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:43:48 +0100 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) 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 From ee4d37edf6146c42bdf9983b92f55fced637e78f Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:44:04 +0100 Subject: [PATCH 3/4] Fix rubocob --- spec/configuration/custom_renderer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/configuration/custom_renderer_spec.rb b/spec/configuration/custom_renderer_spec.rb index 64355e6d..1bc3f488 100644 --- a/spec/configuration/custom_renderer_spec.rb +++ b/spec/configuration/custom_renderer_spec.rb @@ -200,7 +200,7 @@ def build_controller(&block) end expect(run_action(controller, :index)).to match( - [200, { "content-type" => "application/json; charset=utf-8" }, [include("Alice")]] + [200, { "content-type" => "application/json; charset=utf-8" }, [include("Alice")]] ) end end From ce28f74560c336e7bea324c345fccb4dd7f34a4a Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Fri, 17 Jul 2026 14:44:29 +0100 Subject: [PATCH 4/4] Bump version --- lib/rage/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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