File: app.rb

package info (click to toggle)
hiki 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,812 kB
  • ctags: 2,033
  • sloc: ruby: 14,572; lisp: 926; sh: 19; makefile: 16
file content (39 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (3)
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