mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
922d6de4d1
Improve and correct request middleware Request -> Middleware -> Filter -> Route
30 lines
764 B
Crystal
30 lines
764 B
Crystal
require "./spec_helper"
|
|
|
|
class CustomTestHandler < HTTP::Handler
|
|
def call(env)
|
|
env.response << "Kemal"
|
|
call_next env
|
|
end
|
|
end
|
|
|
|
describe "Handler" do
|
|
it "adds custom handler before before_*" do
|
|
filter_middleware = Kemal::Middleware::Filter.new
|
|
filter_middleware._add_route_filter("GET", "/", :before) do |env|
|
|
env.response << " is"
|
|
end
|
|
|
|
filter_middleware._add_route_filter("GET", "/", :before) do |env|
|
|
env.response << " so"
|
|
end
|
|
add_handler CustomTestHandler.new
|
|
|
|
get "/" do |env|
|
|
" Great"
|
|
end
|
|
request = HTTP::Request.new("GET", "/")
|
|
client_response = call_request_on_app(request)
|
|
client_response.status_code.should eq(200)
|
|
client_response.body.should eq("Kemal is so Great")
|
|
end
|
|
end
|