mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
fixed executing filters when before and after is defined at the same time (#612)
This commit is contained in:
parent
218be24221
commit
14aabb8907
2 changed files with 25 additions and 1 deletions
|
@ -183,6 +183,30 @@ describe "Kemal::FilterHandler" do
|
||||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
client_response.body.should eq("true")
|
client_response.body.should eq("true")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class FilterTest
|
class FilterTest
|
||||||
|
|
|
@ -71,7 +71,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
|
|
||||||
private def radix_path(verb : String?, path : String, type : Symbol)
|
private def radix_path(verb : String?, path : String, type : Symbol)
|
||||||
"#{type}/#{verb}/#{path}"
|
"/#{type}/#{verb}/#{path}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
Loading…
Reference in a new issue