Decodes url parameters (#229)

Decode url parameters
This commit is contained in:
Sam Eaton 2016-10-18 07:28:42 -06:00 committed by Serdar Dogruyol
parent 5d71c76554
commit e43b2a3a01
3 changed files with 23 additions and 2 deletions

View file

@ -5,7 +5,7 @@ HTTP_METHODS = %w(get post put patch delete options)
{% for method in HTTP_METHODS %}
def {{method.id}}(path, &block : HTTP::Server::Context -> _)
Kemal::RouteHandler::INSTANCE.add_route({{method}}.upcase, path, &block)
Kemal::RouteHandler::INSTANCE.add_route({{method}}.upcase, path, &block)
end
{% end %}

View file

@ -21,6 +21,10 @@ module Kemal
@json_parsed = false
end
private def decode_url_param(value : String)
value.size == 0 ? value : HTTP::Params.parse(value).first[0]?
end
{% for method in %w(url query body json) %}
def {{method.id}}
# check memoization
@ -45,7 +49,7 @@ module Kemal
def parse_url
if params = @request.url_params
params.each do |key, value|
@url[key.as(String)] = value.as(String)
@url[key.as(String)] = decode_url_param(value).as(String)
end
end
end