Sha256: 511c53bac7958e26556262d09d5108aa8b1935fe3570705fe45c85dbb5c31442

Contents?: true

Size: 772 Bytes

Versions: 3

Compression:

Stored size: 772 Bytes

Contents

module Rack
  class MogileFS
    class Endpoint

      # Adds reproxy support. To activate:
      #
      #     Rack::MogileFS::Endpoint.new :strategy => :reproxy
      module Reproxy
        def initialize(*)
          super
          @options[:strategy] ||= :serve
        end

        def serve_file(path)
          if @options[:strategy] == :reproxy
            reproxy(path)
          else
            super
          end
        end

        def reproxy(path)
          paths = client.get_paths(path)
          file  = File.new(path, nil)

          [ 200, {
            "Content-Type"     => file.content_type,
            "X-Accel-Redirect" => "/reproxy",
            "X-Reproxy-Url"    => paths.join(" ")
          }, [] ]
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-mogilefs-0.3.2 lib/rack/mogilefs/endpoint/reproxy.rb
rack-mogilefs-0.3.1 lib/rack/mogilefs/endpoint/reproxy.rb
rack-mogilefs-0.3.0 lib/rack/mogilefs/endpoint/reproxy.rb