Skip to content

Commit

Permalink
Removes initializer method from static handler (#128)
Browse files Browse the repository at this point in the history
* Removes initializer method from static handler

The initializer method should be defined again since it takes the
same parameters as the HTTP::StaticFileHandler.

* fixup! Removes initializer method from static handler
  • Loading branch information
eliasjpr authored Jul 5, 2017
1 parent 05d4da1 commit 0444c48
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/amber/router/pipe/static.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ require "zlib"
module Amber
module Pipe
class Static < HTTP::StaticFileHandler
property default_file, public_dir

def initialize(public_dir : String, directory_listing = false, fallthrough = true)
@public_dir = File.expand_path public_dir
@fallthrough = !!fallthrough
@default_file = "index.html"
@static_config = {"dir_listing" => false, "gzip" => true}
@directory_listing = directory_listing
end

@directory_listing = false
@fallthrough = false

def call(context : HTTP::Server::Context)
return call_next(context) if context.request.path.not_nil! == "/"
Expand All @@ -26,7 +20,7 @@ module Amber
return
end

config = @static_config
config = static_config
original_path = context.request.path.not_nil!
is_dir_path = original_path.ends_with? "/"
request_path = URI.unescape(original_path)
Expand Down Expand Up @@ -66,6 +60,10 @@ module Amber
end
end

private def static_config
{ "dir_listing" => @directory_listing, "gzip" => true }
end

private def etag(context, file_path)
etag = %{W/"#{File.lstat(file_path).mtime.epoch.to_s}"}
context.response.headers["ETag"] = etag
Expand All @@ -81,7 +79,7 @@ module Amber
end

private def serve_file(env, path : String, mime_type : String? = nil)
config = @static_config
config = static_config
file_path = File.expand_path(path, Dir.current)
mime_type ||= mime_type(file_path)
env.response.content_type = mime_type
Expand Down Expand Up @@ -162,5 +160,7 @@ module Amber
end
end
end


end
end

0 comments on commit 0444c48

Please sign in to comment.