Accepts requests with query string
This commit is contained in:
parent
7e841a88b2
commit
8b1447b68d
3 changed files with 23 additions and 1 deletions
|
@ -11,6 +11,16 @@ describe "Frank::Handler" do
|
|||
response.body.should eq("hello")
|
||||
end
|
||||
|
||||
it "routes request with query string" do
|
||||
frank = Frank::Handler.new
|
||||
frank.add_route "GET", "/" do |ctx|
|
||||
"hello #{ctx.params["message"]}"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/?message=world")
|
||||
response = frank.call(request)
|
||||
response.body.should eq("hello world")
|
||||
end
|
||||
|
||||
it "sets content type" do
|
||||
frank = Frank::Handler.new
|
||||
frank.add_route "GET", "/" do |env|
|
||||
|
|
|
@ -11,4 +11,8 @@ class Frank::Context
|
|||
def response?
|
||||
@response
|
||||
end
|
||||
|
||||
def params
|
||||
request.params
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require "http/server"
|
||||
require "cgi"
|
||||
|
||||
class Frank::Handler < HTTP::Handler
|
||||
INSTANCE = new
|
||||
|
@ -17,10 +18,17 @@ class Frank::Handler < HTTP::Handler
|
|||
end
|
||||
|
||||
def exec_request(request)
|
||||
components = request.path.split "/"
|
||||
uri = request.uri
|
||||
components = uri.path.not_nil!.split "/"
|
||||
@routes.each do |route|
|
||||
params = route.match(request.method, components)
|
||||
if params
|
||||
if query = uri.query
|
||||
CGI.parse(query) do |key, value|
|
||||
params[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
frank_request = Request.new(request, params)
|
||||
context = Context.new(frank_request)
|
||||
begin
|
||||
|
|
Loading…
Reference in a new issue