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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "../probe"
|
require_relative "../probe"
|
||||||
|
require_relative "../util/mime"
|
||||||
|
|
||||||
module Landline
|
module Landline
|
||||||
module Handlers
|
module Handlers
|
||||||
|
@ -18,12 +19,18 @@ module Landline
|
||||||
# Method callback on successful request navigation.
|
# Method callback on successful request navigation.
|
||||||
# Tries to serve files matched by handler
|
# Tries to serve files matched by handler
|
||||||
# @param request [Landline::Request]
|
# @param request [Landline::Request]
|
||||||
# @return [Boolean] true if file was found
|
# @return [Boolean, Array] true if file was found
|
||||||
def process(request)
|
def process(request)
|
||||||
path = File.expand_path(request.filepath)
|
path = File.expand_path(request.filepath)
|
||||||
return unless path.start_with? @properties["path"]
|
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
|
rescue StandardError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue