Skip to content

Commit

Permalink
Merge pull request #72 from Sija/patch-1
Browse files Browse the repository at this point in the history
Don't send `charset` with `application/json` content type
  • Loading branch information
grkek authored Dec 4, 2024
2 parents 58d3630 + 0b5191d commit 7eda3e8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
12 changes: 0 additions & 12 deletions spec/context_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/grip/extensions/context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7eda3e8

Please sign in to comment.