Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send charset with application/json content type #72

Merged
merged 2 commits into from
Dec 4, 2024
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
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
Loading