1 2 3 4 5 6 7 8 9 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 35 36 37 38 39
|
require 'rubygems'
require 'rack'
require 'hiki/config'
require 'hiki/xmlrpc'
$LOAD_PATH.unshift(File.dirname(__FILE__))
module Hiki
class App
def initialize(config_path = 'hikiconf.rb')
@config_path = config_path
end
def call(env)
request = Rack::Request.new(env)
# TODO use Rack::Request#env or other methods instead of ENV
# HACK replace ENV values to web application environment
env.each{|k,v| ENV[k] = v.to_s unless /\Arack\./ =~ k }
conf = Hiki::Config.new(@config_path)
response = nil
if %r|text/xml| =~ request.content_type and request.post?
server = Hiki::XMLRPCServer.new(conf, request)
response = server.serve
else
db = conf.database
db.open_db do
command = Hiki::Command.new(request, db, conf)
response = command.dispatch
end
end
# [body, status, headers]
# Rack::Response.new(*response){|r|
# }.finish
response.header.delete('status')
response.finish
end
end
end
|