From c086cbbfee30e54f36d4a4db45eda38ed8a182c7 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sat, 30 Nov 2024 07:10:11 +0100 Subject: [PATCH 1/2] Don't send `charset` with `application/json` content type --- src/grip/extensions/context.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grip/extensions/context.cr b/src/grip/extensions/context.cr index 1b6d9b7..cc52bb1 100644 --- a/src/grip/extensions/context.cr +++ b/src/grip/extensions/context.cr @@ -92,7 +92,7 @@ module Grip end # Sends a response with the content formated as json. - def json(content, content_type = "application/json; charset=UTF-8") + def json(content, content_type = "application/json") @response.headers.merge!({"Content-Type" => content_type}) @response.print(content.to_json) self From 0b5191dba4ef43404d426f73cde2416fbe5be8d4 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 4 Dec 2024 01:05:08 +0100 Subject: [PATCH 2/2] Remove obsolete test --- spec/context_spec.cr | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/spec/context_spec.cr b/spec/context_spec.cr index 29216c6..a144c79 100644 --- a/spec/context_spec.cr +++ b/spec/context_spec.cr @@ -80,18 +80,6 @@ describe "Context" do ("UTF-8".in? client_response.headers["Content-Type"]).should be_true end - it "encodes json in utf-8" do - http_handler = Grip::Routers::Http.new - http_handler.add_route "GET", "/", ExampleController.new, [:none], ->(context : HTTP::Server::Context) do - context.json({:message => "👋🏼 grip"}).halt - end - - request = HTTP::Request.new("GET", "/") - client_response = call_request_on_app(request, http_handler) - client_response.body.should eq "{\"message\":\"👋🏼 grip\"}" - ("UTF-8".in? client_response.headers["Content-Type"]).should be_true - end - it "encodes html in utf-8" do http_handler = Grip::Routers::Http.new http_handler.add_route "GET", "/", ExampleController.new, [:none], ->(context : HTTP::Server::Context) do