Class: Imageproxy::Server
- Inherits:
-
Object
- Object
- Imageproxy::Server
- Defined in:
- lib/imageproxy/server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
11 12 13 |
# File 'lib/imageproxy/server.rb', line 11 def initialize @file_server = Rack::File.new(File.join(File.(File.dirname(__FILE__)), "..", "public")) end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/imageproxy/server.rb', line 15 def call(env) request = Rack::Request.new(env) = Options.new(request.path_info, request.params) user_agent = request.env["HTTP_USER_AGENT"] cachetime = config(:cache_time) ? config(:cache_time) : 86400 case .command when "convert", "process", nil check_signature request, check_domain check_size file = convert_file(, user_agent) class << file alias to_path path end file.open [200, {"Cache-Control" => "max-age=#{cachetime}, must-revalidate"}.merge(content_type(file, )), file] when "identify" check_signature request, check_domain [200, {"Content-Type" => "text/plain"}, [Identify.new().execute(user_agent)]] when "selftest" [200, {"Content-Type" => "text/html"}, [Selftest.html(request, config?(:signature_required), config(:signature_secret))]] else @file_server.call(env) end rescue STDERR.puts "Request failed: #{}" STDERR.puts $! STDERR.puts $!.backtrace.join("\n") if config?(:verbose) [500, {"Content-Type" => "text/plain"}, ["Error (#{$!})"]] end |