Creates a new RubyHandler instance for the Apache web server. It is to be installed as a custom 404 ErrorDocument handler.
# File lib/apache/image_resizer.rb, line 42 def initialize(options = {}) @verbosity = options[:verbosity] || DEFAULT_VERBOSITY @max_dim = options[:max_dim] || DEFAULT_MAX_DIM @prefix_re = options[:prefix_re] || DEFAULT_PREFIX_RE @source_dir = options[:source_dir] || DEFAULT_SOURCE_DIR @proxy_cache = options[:proxy_cache] || DEFAULT_PROXY_CACHE @enlarge = options[:enlarge] @secret = options[:secret] end
If the current request
asked for a resource that's not
there, it will be checked for resize directives and treated accordingly. If
no matching resource could be found, the original error will be thrown.
# File lib/apache/image_resizer.rb, line 56 def handler(request, &block) request.add_common_vars # REDIRECT_URL, REDIRECT_QUERY_STRING env = request.subprocess_env url = env['REDIRECT_URL'] query = env['REDIRECT_QUERY_STRING'] url += "?#{query}" unless query.nil? || query.empty? block ||= lambda { |msg| log(2) { "#{url} - Elapsed #{Time.now - request.request_time} [#{msg}]" } } path, prefix, directives, dir = parse_url(url, base = request.path_info, @prefix_re, &block) return DECLINED unless path log(2) {{ :Base => base, :Prefix => prefix, :Dir => dir, :Path => path }} source, target = get_paths(request, path, base, prefix, @source_dir, dir, @proxy_cache, @secret) if source log(2) {{ :Source => source, :Target => target, :Directives => directives }} return DECLINED unless img = resize(source, target, directives, @enlarge, &block) end return DECLINED unless send_image(request, target, img, &block) log { "#{url} - Elapsed #{Time.now - request.request_time}" } OK end