Skip to content
Browse files

Got the etags under control and now using a Rack::Static like impleme…

…ntation using Rack::File (thanks to wycats for prodding in the right direction)
  • Loading branch information...
1 parent 4bc77f0 commit f56a022021d93627118f207bc234c238086b18e1 @parndt parndt committed
Showing with 9 additions and 19 deletions.
  1. +1 −1 VERSION
  2. +8 −18 vendor/plugins/themes/lib/theme_server.rb
View
2 VERSION
@@ -1 +1 @@
-0.9.6.11
+0.9.6.12
View
26 vendor/plugins/themes/lib/theme_server.rb
@@ -9,27 +9,17 @@ def initialize(app)
end
def call(env)
- if env["PATH_INFO"] =~ /^\/theme/
- relative_path = env["PATH_INFO"].gsub(/^\/theme\//, '')
-
- if (file_path = Rails.root.join("themes", RefinerySetting[:theme], relative_path)).exist?
- # generate an etag for client-side caching.
- etag = Digest::MD5.hexdigest("#{file_path.to_s}#{file_path.mtime}")
- unless (env["HTTP_IF_NONE_MATCH"] == etag and RefinerySetting.find_or_set(:themes_use_etags, false) == true)
- [200, {
- "Content-Type" => Rack::Mime.mime_type(file_path.extname),
- "Cache-Control" => "public",
- "ETag" => etag
- }, file_path.open]
- else
- [304, {}, []]
- end
+ relative_path = env["PATH_INFO"].gsub(/^\/theme\//, '')
+ if (env["PATH_INFO"]) =~ /^\/theme/ and (file_path=Rails.root.join("themes", RefinerySetting[:theme], relative_path)).exist?
+ unless ((etag = Digest::MD5.hexdigest("#{file_path.to_s}#{file_path.mtime}")) == env["HTTP_IF_NONE_MATCH"])
+ env["PATH_INFO"] = relative_path
+ status, headers, body = Rack::File.new(Rails.root.join("themes", RefinerySetting[:theme])).call(env)
+ [status, headers.update({"ETag" => etag}), body]
else
- [404, {"Content-Type" => "text/html"}, ["Not Found"]]
+ [304, {"ETag" => etag}, []]
end
else
- status, headers, response = @app.call(env)
- [status, headers, response]
+ @app.call(env)
end
end

0 comments on commit f56a022

Please sign in to comment.
Something went wrong with that request. Please try again.