Fix parsing JSON params when "charset" is present in "Content-Type" header (#193)

Resolves case when `Content-Type` headers is passed in form of `application/json; charset=utf-8`
This commit is contained in:
Sijawusz Pur Rahnama 2016-08-11 21:29:29 +02:00 committed by Serdar Dogruyol
parent d4e96c7b44
commit 28859fbdb8
2 changed files with 15 additions and 1 deletions

View file

@ -55,7 +55,7 @@ module Kemal
# If request body is a JSON Array it's added into `params` as `_json` and can be accessed
# like params["_json"]
def parse_json
return unless @request.body && @request.headers["Content-Type"]? == APPLICATION_JSON
return unless @request.body && @request.headers["Content-Type"]?.try(&.[APPLICATION_JSON]?)
body = @request.body.as(String)
case json = JSON.parse(body).raw