Module: Rack::MogileFS::Endpoint::Reproxy

Included in:
Rack::MogileFS::Endpoint
Defined in:
lib/rack/mogilefs/endpoint/reproxy.rb

Overview

Adds reproxy support. To activate:

Rack::MogileFS::Endpoint.new :strategy => :reproxy

Instance Method Summary collapse

Instance Method Details

#initializeObject



9
10
11
12
# File 'lib/rack/mogilefs/endpoint/reproxy.rb', line 9

def initialize(*)
  super
  @options[:strategy] ||= :serve
end

#reproxy(path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/mogilefs/endpoint/reproxy.rb', line 22

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

#serve_file(path) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rack/mogilefs/endpoint/reproxy.rb', line 14

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