Now supports multiple query strings

This commit is contained in:
Sdogruyol 2015-10-26 20:49:28 +02:00
parent efe75196f7
commit 4a6fb6cf66
2 changed files with 13 additions and 4 deletions

View file

@ -21,6 +21,16 @@ describe "Kemal::Handler" do
response.body.should eq("hello world")
end
it "routes request with multiple query strings" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |ctx|
"hello #{ctx.params["message"]} time #{ctx.params["time"]}"
end
request = HTTP::Request.new("GET", "/?message=world&time=now")
response = kemal.call(request)
response.body.should eq("hello world time now")
end
it "route parameter has more precedence than query string arguments" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/:message" do |ctx|

View file

@ -23,10 +23,9 @@ class Kemal::Handler < HTTP::Handler
params = route.match(request.method, components)
if params
if query = request.query
split = query.split("=")
key = split[0]
value = split[1]
params[key] ||= value
HTTP::Params.parse(query) do |key, value|
params[key] ||= value
end
end
if body = request.body