Skip to content

Commit c77d13b

Browse files
committed
Use MIME::Types to infer the correct content_type
These case statements were duplicated and didn't provide anything useful over the provided MIME::Types module.
1 parent dfeb417 commit c77d13b

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

lib/logstash/kibana.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require "ftw" # gem ftw
33
require "sinatra/base" # gem sinatra
44
require "optparse"
5+
require "mime/type"
56

67
class Rack::Handler::FTW
78
alias_method :handle_connection_, :handle_connection
@@ -41,15 +42,7 @@ def static_file
4142
path = File.join(docroot, *request.path_info.split("/"))
4243
if File.exists?(path)
4344
ext = path.split(".").last
44-
case ext
45-
when "js"; content_type "application/javascript"
46-
when "css"; content_type "text/css"
47-
when "jpg"; content_type "image/jpeg"
48-
when "jpeg"; content_type "image/jpeg"
49-
when "png"; content_type "image/png"
50-
when "gif"; content_type "image/gif"
51-
end
52-
45+
content_type MIME::Types.type_for(ext).first.to_s
5346
body File.new(path, "r").read
5447
else
5548
status 404

lib/logstash/web/controllers/static_files.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "sinatra/base"
2+
require "mime/type"
23

34
class LogStash::Web::Server < Sinatra::Base
45
get '/js/*' do static_file end
@@ -15,15 +16,7 @@ def static_file
1516
#p :static => path
1617
if File.exists?(path)
1718
ext = path.split(".").last
18-
case ext
19-
when "js"; content_type "application/javascript"
20-
when "css"; content_type "text/css"
21-
when "jpg"; content_type "image/jpeg"
22-
when "jpeg"; content_type "image/jpeg"
23-
when "png"; content_type "image/png"
24-
when "gif"; content_type "image/gif"
25-
end
26-
19+
content_type MIME::Types.type_for(ext).first.to_s
2720
body File.new(path, "r").read
2821
else
2922
status 404

0 commit comments

Comments
 (0)