fixed executing filters when before and after is defined at the same time (#612)

This commit is contained in:
Anton Maminov 2021-09-01 16:25:21 +03:00 committed by GitHub
parent 218be24221
commit 14aabb8907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -183,6 +183,30 @@ describe "Kemal::FilterHandler" do
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should eq("true")
end
it "executes code before and after request" do
before_filter = FilterTest.new
before_filter.modified = "false"
after_filter = FilterTest.new
after_filter.modified = "false"
filter_middleware = Kemal::FilterHandler.new
filter_middleware._add_route_filter("ALL", "*", :before) { before_filter.modified = "true" }
filter_middleware._add_route_filter("ALL", "*", :after) { after_filter.modified = "true" }
kemal = Kemal::RouteHandler::INSTANCE
kemal.add_route "GET", "/" { "#{before_filter.modified}-#{after_filter.modified}" }
before_filter.modified.should eq("false")
after_filter.modified.should eq("false")
request = HTTP::Request.new("GET", "/")
create_request_and_return_io_and_context(filter_middleware, request)
io_with_context = create_request_and_return_io_and_context(kemal, request)[0]
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.body.should eq("true-true")
end
end
class FilterTest

View File

@ -71,7 +71,7 @@ module Kemal
end
private def radix_path(verb : String?, path : String, type : Symbol)
"#{type}/#{verb}/#{path}"
"/#{type}/#{verb}/#{path}"
end
# :nodoc: