mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Merge pull request #20 from ilatif/master
Implemented HTTP `HEAD` method.
This commit is contained in:
commit
a37d45cd22
2 changed files with 20 additions and 0 deletions
|
@ -167,4 +167,21 @@ describe "Kemal::Handler" do
|
|||
response.body.should eq("Hello World from DELETE")
|
||||
end
|
||||
|
||||
it "can process HTTP HEAD requests for defined GET routes" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/" do |env|
|
||||
"Hello World from GET"
|
||||
end
|
||||
request = HTTP::Request.new("HEAD", "/")
|
||||
response = kemal.call(request)
|
||||
response.status_code.should eq(200)
|
||||
end
|
||||
|
||||
it "can't process HTTP HEAD requests for undefined GET routes" do
|
||||
kemal = Kemal::Handler.new
|
||||
request = HTTP::Request.new("HEAD", "/")
|
||||
response = kemal.call(request)
|
||||
response.status_code.should eq(404)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,6 +15,9 @@ class Kemal::Handler < HTTP::Handler
|
|||
|
||||
def add_route(method, path, &handler : Kemal::Context -> _)
|
||||
@routes << Route.new(method, path, &handler)
|
||||
|
||||
# Registering HEAD route for defined GET routes.
|
||||
@routes << Route.new("HEAD", path, &handler) if method == "GET"
|
||||
end
|
||||
|
||||
def process_request(request)
|
||||
|
|
Loading…
Reference in a new issue