mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Now supports multiple query strings
This commit is contained in:
parent
efe75196f7
commit
4a6fb6cf66
2 changed files with 13 additions and 4 deletions
|
@ -21,6 +21,16 @@ describe "Kemal::Handler" do
|
||||||
response.body.should eq("hello world")
|
response.body.should eq("hello world")
|
||||||
end
|
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
|
it "route parameter has more precedence than query string arguments" do
|
||||||
kemal = Kemal::Handler.new
|
kemal = Kemal::Handler.new
|
||||||
kemal.add_route "GET", "/:message" do |ctx|
|
kemal.add_route "GET", "/:message" do |ctx|
|
||||||
|
|
|
@ -23,11 +23,10 @@ class Kemal::Handler < HTTP::Handler
|
||||||
params = route.match(request.method, components)
|
params = route.match(request.method, components)
|
||||||
if params
|
if params
|
||||||
if query = request.query
|
if query = request.query
|
||||||
split = query.split("=")
|
HTTP::Params.parse(query) do |key, value|
|
||||||
key = split[0]
|
|
||||||
value = split[1]
|
|
||||||
params[key] ||= value
|
params[key] ||= value
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if body = request.body
|
if body = request.body
|
||||||
HTTP::Params.parse(request.body.not_nil!) do |key, value|
|
HTTP::Params.parse(request.body.not_nil!) do |key, value|
|
||||||
|
|
Loading…
Reference in a new issue