Added MIME types library for static file serving
This commit is contained in:
parent
56e3907250
commit
960dbf92ea
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../probe"
|
||||
require_relative "../util/mime"
|
||||
|
||||
module Landline
|
||||
module Handlers
|
||||
|
@ -18,12 +19,18 @@ module Landline
|
|||
# Method callback on successful request navigation.
|
||||
# Tries to serve files matched by handler
|
||||
# @param request [Landline::Request]
|
||||
# @return [Boolean] true if file was found
|
||||
# @return [Boolean, Array] true if file was found
|
||||
def process(request)
|
||||
path = File.expand_path(request.filepath)
|
||||
return unless path.start_with? @properties["path"]
|
||||
|
||||
File.open(path.delete_suffix("/"))
|
||||
filepath = path.delete_suffix("/")
|
||||
|
||||
[200,
|
||||
{
|
||||
"content-type" => Landline::MIME.get_mime_type(filepath)
|
||||
},
|
||||
File.open(filepath)]
|
||||
rescue StandardError
|
||||
false
|
||||
end
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue