Class: OMF::Web::Rack::ContentHandler

Inherits:
Base::LObject
  • Object
show all
Defined in:
lib/omf-web/rack/content_handler.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omf-web/rack/content_handler.rb', line 10

def call(env)
  req = ::Rack::Request.new(env)
  begin
    c_id = req.path_info[1 .. -1]
    c_proxy = OMF::Web::ContentProxy[c_id]
    unless c_proxy
      raise MissingArgumentException.new "Can't find content proxy '#{c_id}'"
    end
    method = "on_#{req.request_method().downcase}"
    body, headers = c_proxy.send(method.to_sym, req)
  rescue OMF::Web::ReadOnlyContentRepositoryException
    return [403, {"Content-Type" => 'text'}, "Read-only repository"]
  rescue MissingArgumentException => mex
    debug mex
    return [412, {"Content-Type" => 'text'}, [mex.to_s]]
  rescue Exception => ex
    error ex
    debug ex.to_s + "\n\t" + ex.backtrace.join("\n\t")
    return [500, {"Content-Type" => 'text'}, [ex.to_s]]
  end
  if headers.kind_of? String
    headers = {"Content-Type" => headers}
  end
  [200, headers, [body]]
end