[Nitro] [PATCH] first attempt for *new* mongrel-adapter
Alexander Lazic
al-nitrogen at none.at
Sat Aug 5 09:22:41 EDT 2006
Hi,
attached the first attempt to mongrelify the adapter ;-)
At the moment i see some pitfalls:
1.) i have *borrow* some code from lib/nitro/cgi.rb because i haven't
found a easy way to get the header from
Cgi.response_headers(context).
This methode return the headers as string and i don't like to make
hash=>string=>hash :-(
@George: howabout to add a methode Cgi.response_headers_as_hash or
is there a easier way in ruby which i don't know?!
2.) Are in server.options also the --debug flag from the commandline?
3.) It's a quick hack from a ruby newbie threfore somethings could be
*better* ;-)
I'am not sure if the Mongrel::Configurator is the *best* or preferd way
to setup the mongrel but i hope somone can us help in this issue ;-)))
Please tell me your thoughts ;-)
Regards
Alex
-------------- next part --------------
--- /home/al/progs/ruby/lib/ruby/gems/1.8/gems/nitro-0.31.0/lib/nitro/adapter/mongrel.rb.orig 2006-08-05 09:55:03.000000000 +0200
+++ /home/al/progs/ruby/lib/ruby/gems/1.8/gems/nitro-0.31.0/lib/nitro/adapter/mongrel.rb 2006-08-05 15:11:47.000000000 +0200
@@ -35,38 +35,30 @@
class << self
attr_accessor :mongrel
+ attr_accessor :mongrel_config
# Start the Webrick adapter.
def start(server)
# TODO add logging.
- mongrel_options = server.options.dup
-
- mongrel_options.update(
- :BindAddress => server.address,
- :Port => server.port,
- :DocumentRoot => server.public_root
- )
-
- @mongrel = ::Mongrel::HttpServer.new(mongrel_options[:BindAddress],
- mongrel_options[:Port])
-
- trap('INT') { exit } # works until you use breakpoint... why?
-
- @mongrel.register('/', MongrelAdapter.new(server))
-
- initialize_mongrel(server)
-
- @mongrel.run
- @mongrel_thread = @mongrel.acceptor
- @mongrel_thread.join
+ @mongrel_config = ::Mongrel::Configurator.new :host => server.address do
+ listener :port => server.port do
+ uri "/", :handler => MongrelAdapter.new(server)
+ trap('INT') { exit } # works until you use breakpoint... why?
+# debug "/"
+ run
+ end
+ end
+ @mongrel_config.log("Started mongel on " + server.address + ":" + server.port.to_s)
+ @mongrel_config.join
end
# Stop the Mongrel adapter.
def stop
- @mongrel_thread.kill
+ @mongrel_config.log("Stopped mongel on " + server.address + ":" + server.port.to_s)
+ @mongrel_config.stop
end
# Override this method to perform customized mongrel
@@ -139,12 +131,20 @@
Cgi.parse_cookies(context)
context.render(path)
-
- res.status = context.status
- res.header.out << Cgi.response_headers(context)
- res.body << context.out
-
+ # what is the error code if a request without a handler is comming?! al 2006-Aug-05
+ res.start(context.status,true) do |head,out|
+ context.response_headers.each do |key, value|
+ head[key] = value
+ end
+
+ context.response_cookies.each do |cookie|
+ head['Set-Cookie:'] = cookie
+ end if context.response_cookies
+
+ out.write(context.out)
+ end
+
context.close
ensure
Og.manager.put_store if defined?(Og) and Og.respond_to?(:manager) and Og.manager
More information about the Nitro-general
mailing list