Changeset 1482
- Timestamp:
- 06/22/05 12:59:36 (3 years ago)
- Files:
-
- trunk/actionpack/lib/action_controller/cgi_process.rb (modified) (2 diffs)
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/lib/dispatcher.rb (modified) (1 diff)
- trunk/railties/lib/webrick_server.rb (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/cgi_process.rb
r1336 r1482 125 125 end 126 126 127 def out 127 def out(output = $stdout) 128 128 convert_content_type!(@headers) 129 $stdout.binmode if $stdout.respond_to?(:binmode)130 $stdout.sync = false129 output.binmode if output.respond_to?(:binmode) 130 output.sync = false if output.respond_to?(:sync=) 131 131 132 132 begin 133 print @cgi.header(@headers)133 output.write(@cgi.header(@headers)) 134 134 135 135 if @cgi.send(:env_table)['REQUEST_METHOD'] == 'HEAD' … … 138 138 @body.call(self) 139 139 else 140 print @body140 output.write(@body) 141 141 end 142 142 rescue Errno::EPIPE => e trunk/railties/CHANGELOG
r1480 r1482 1 1 *SVN* 2 3 * Removed the mutex from the WEBrick adapter under the production environment so concurrent requests can be served 2 4 3 5 * Fixed that mailer generator generated fixtures/plural while units expected fixtures/singular #1457 [Scott Barron] trunk/railties/lib/dispatcher.rb
r1278 r1482 26 26 class Dispatcher 27 27 class << self 28 def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS )28 def dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout) 29 29 begin 30 30 request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi) 31 31 prepare_application 32 ActionController::Routing::Routes.recognize!(request).process(request, response).out 32 ActionController::Routing::Routes.recognize!(request).process(request, response).out(output) 33 33 rescue Object => exception 34 ActionController::Base.process_with_exception(request, response, exception).out 34 ActionController::Base.process_with_exception(request, response, exception).out(output) 35 35 ensure 36 36 reset_application trunk/railties/lib/webrick_server.rb
r1433 r1482 8 8 9 9 ABSOLUTE_RAILS_ROOT = File.expand_path(RAILS_ROOT) 10 11 class CGI 12 def stdinput 13 @stdin || $stdin 14 end 15 16 def stdinput=(input) 17 @stdin = input 18 end 19 20 def env_table 21 @env_table || ENV 22 end 23 24 def env_table=(table) 25 @env_table = table 26 end 27 end 10 28 11 29 class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet … … 19 37 20 38 trap("INT") { server.shutdown } 39 40 require File.join(@server_options[:server_root], "..", "config", "environment") unless defined?(RAILS_ROOT) 41 require "dispatcher" 42 21 43 server.start 22 44 end … … 32 54 begin 33 55 unless handle_file(req, res) 34 REQUEST_MUTEX.lock 56 REQUEST_MUTEX.lock unless RAILS_ENV == 'production' 35 57 unless handle_dispatch(req, res) 36 58 raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." … … 38 60 end 39 61 ensure 40 REQUEST_MUTEX.unlock if REQUEST_MUTEX.locked? 62 unless RAILS_ENV == 'production' 63 REQUEST_MUTEX.unlock if REQUEST_MUTEX.locked? 64 end 41 65 end 42 66 end … … 45 69 begin 46 70 req = req.dup 47 48 71 path = req.path.dup 49 72 … … 64 87 end 65 88 66 def handle_dispatch(req, res, origin = nil) 67 env = req.meta_vars.clone 68 env.delete "SCRIPT_NAME" 69 env["QUERY_STRING"] = req.request_uri.query 70 env["REQUEST_URI"] = origin if origin 71 72 data = nil 73 $old_stdin, $old_stdout = $stdin, $stdout 74 $stdin, $stdout = StringIO.new(req.body || ""), StringIO.new 89 def handle_dispatch(req, res, origin = nil) 90 data = StringIO.new 91 Dispatcher.dispatch(create_cgi(req, origin), ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, data) 75 92 76 begin 77 require 'cgi' 78 CGI.send(:define_method, :env_table) { env } 79 80 load File.join(@server_options[:server_root], "dispatch.rb") 81 82 $stdout.rewind 83 data = $stdout.read 84 ensure 85 $stdin, $stdout = $old_stdin, $old_stdout 86 end 87 88 raw_header, body = *data.split(/^[\xd\xa]+/on, 2) 89 header = WEBrick::HTTPUtils::parse_header(raw_header) 90 if /^(\d+)/ =~ header['status'][0] 91 res.status = $1.to_i 92 header.delete('status') 93 end 94 res.cookies.concat header.delete('set-cookie') 93 header, body = extract_header_and_body(data) 94 assign_status(res, header) 95 res.cookies.concat(header.delete('set-cookie')) 95 96 header.each { |key, val| res[key] = val.join(", ") } 96 97 … … 101 102 return false 102 103 end 104 105 private 106 def create_cgi(req, origin) 107 cgi = CGI.new 108 cgi.env_table = create_env_table(req, origin) 109 cgi.stdinput = req.body || "" 110 return cgi 111 end 112 113 def create_env_table(req, origin) 114 env = req.meta_vars.clone 115 env.delete "SCRIPT_NAME" 116 env["QUERY_STRING"] = req.request_uri.query 117 env["REQUEST_URI"] = origin if origin 118 return env 119 end 120 121 def extract_header_and_body(data) 122 data.rewind 123 data = data.read 124 125 raw_header, body = *data.split(/^[\xd\xa]+/on, 2) 126 header = WEBrick::HTTPUtils::parse_header(raw_header) 127 128 return header, body 129 end 130 131 def assign_status(res, header) 132 if /^(\d+)/ =~ header['status'][0] 133 res.status = $1.to_i 134 header.delete('status') 135 end 136 end 103 137 end