# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

$LOAD_PATH << "../../lib" unless $LOAD_PATH.include?("../../lib")
require "qwik/webrick"

module Qwik
  class Servlet < WEBrick::HTTPServlet::AbstractServlet
    def do_GET(request, response)
      config = @server[:QwikConfig]
      memory = @server[:QwikMemory]

      req = Request.new(config)
      req.parse_webrick(request)

      res = Response.new(config)
      res.set_webrick(response)

      action = Action.new(config, memory, req, res)
      action.run

      res.setback(response)

      qlog = memory[:accesslog]
      qlog.log(request, response, req, res) if qlog # take log

      if res.basicauth
	proc = res.basicauth
	WEBrick::HTTPAuth::basic_auth(request, response, "qwik", &proc)
      end
    end

    alias do_POST do_GET
  end
end
