48: def start(env=ENV, stdin=$stdin, stdout=$stdout)
49: sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
50: req = HTTPRequest.new(@config)
51: res = HTTPResponse.new(@config)
52: unless @config[:NPH] or defined?(MOD_RUBY)
53: def res.setup_header
54: unless @header["status"]
55: phrase = HTTPStatus::reason_phrase(@status)
56: @header["status"] = "#{@status} #{phrase}"
57: end
58: super
59: end
60: def res.status_line
61: ""
62: end
63: end
64:
65: begin
66: req.parse(sock)
67: req.script_name = (env["SCRIPT_NAME"] || File.expand_path($0)).dup
68: req.path_info = (env["PATH_INFO"] || "").dup
69: req.query_string = env["QUERY_STRING"]
70: req.user = env["REMOTE_USER"]
71: res.request_method = req.request_method
72: res.request_uri = req.request_uri
73: res.request_http_version = req.http_version
74: res.keep_alive = req.keep_alive?
75: self.service(req, res)
76: rescue HTTPStatus::Error => ex
77: res.set_error(ex)
78: rescue HTTPStatus::Status => ex
79: res.status = ex.code
80: rescue Exception => ex
81: @logger.error(ex)
82: res.set_error(ex, true)
83: ensure
84: req.fixup
85: if defined?(MOD_RUBY)
86: res.setup_header
87: Apache.request.status_line = "#{res.status} #{res.reason_phrase}"
88: Apache.request.status = res.status
89: table = Apache.request.headers_out
90: res.header.each{|key, val|
91: case key
92: when /^content-encoding$/i
93: Apache::request.content_encoding = val
94: when /^content-type$/i
95: Apache::request.content_type = val
96: else
97: table[key] = val.to_s
98: end
99: }
100: res.cookies.each{|cookie|
101: table.add("Set-Cookie", cookie.to_s)
102: }
103: Apache.request.send_http_header
104: res.send_body(sock)
105: else
106: res.send_response(sock)
107: end
108: end
109: end