Treat HTTP::Request body as IO. Fixes #257

This commit is contained in:
sdogruyol 2016-11-24 12:07:39 +03:00
parent f11b0e07e4
commit 3b9a3f84ab
3 changed files with 22 additions and 4 deletions

View File

@ -9,7 +9,11 @@ class HTTP::Server
def params
@request.url_params ||= route_lookup.params
@params ||= Kemal::ParamParser.new(@request)
@params ||= if @request.param_parser
@request.param_parser.not_nil!
else
Kemal::ParamParser.new(@request)
end
end
def redirect(url, status_code = 302)

View File

@ -75,8 +75,20 @@ module Kemal
end
end
def parse_part(part)
HTTP::Params.parse(part.to_s || "")
def parse_part(part : IO?)
if part
HTTP::Params.parse(part.gets_to_end)
else
HTTP::Params.parse("")
end
end
def parse_part(part : String?)
if part
HTTP::Params.parse(part.to_s)
else
HTTP::Params.parse("")
end
end
end
end

View File

@ -2,6 +2,7 @@
class HTTP::Request
property override_method
property url_params : Hash(String, String)?
getter param_parser : Kemal::ParamParser?
def override_method
@override_method ||= check_for_method_override!
@ -18,7 +19,8 @@ class HTTP::Request
private def check_for_method_override!
@override_method = @method
if @method == "POST"
params = Kemal::ParamParser.new(self).body
@param_parser = Kemal::ParamParser.new(self)
params = @param_parser.not_nil!.body
if params.has_key?("_method") && HTTP::Request.override_method_valid?(params["_method"])
@override_method = params["_method"]
end