Sha256: fa0667e6b2137dfd49900f37c6cae344a368c2fd0ffff8785886350bcf14014f

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

require 'omf_common/lobject'
require 'omf-web/rack/rack_exceptions'
require 'omf-web/content/content_proxy'

module OMF::Web::Rack
      
  class ContentHandler < OMF::Common::LObject
    
    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 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
  end # ContentHandler
  
end # OMF:Web


      
        

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
omf_web-1.0.0 lib/omf-web/rack/content_handler.rb
omf_web-0.9.9 lib/omf-web/rack/content_handler.rb
omf_web-0.9.8 lib/omf-web/rack/content_handler.rb
omf_web-0.9.7 lib/omf-web/rack/content_handler.rb
omf_web-0.9.6 lib/omf-web/rack/content_handler.rb
omf_web-0.9.5 lib/omf-web/rack/content_handler.rb
omf_web-0.9.4 lib/omf-web/rack/content_handler.rb
omf_web-0.9.3 lib/omf-web/rack/content_handler.rb
omf_web-0.9.1 lib/omf-web/rack/content_handler.rb
omf_web-0.9 lib/omf-web/rack/content_handler.rb