The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Holy Great CGI In Heaven!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Holy Great CGI In Heaven! Posted: Jan 1, 2005 10:51 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Holy Great CGI In Heaven!
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

I know this is a dead simple library, but I’ve been wanting this forever and just not getting around to it. Tanaka Akira presents webapp, a generic interface for writing server-neutral CGIs. Supports CGI, FastCGI,i WEBrick, mod_ruby and command-line interface. This goes in Hobix.

 #!/path/to/ruby
 require 'webapp'

 WebApp do |webapp|
   webapp.puts <<_END_
     current time: #{Time.now}
     pid: #{$$}
     self: #{self.inspect}

     request_method: #{webapp.request_method}
     server_name: #{webapp.server_name}
     server_port: #{webapp.server_port}
     script_name: #{webapp.script_name}
     path_info: #{webapp.path_info}
     query_string: #{webapp.query_string}
     server_protocol: #{webapp.server_protocol}
     remote_addr: #{webapp.remote_addr}
     content_type: #{webapp.content_type}

     --- request headers ---
 _END_
   webapp.each_request_header do |k, v|
     webapp.puts "#{k}: #{v}" 
   end
 end

If you’re wondering why the documentation is so sparse, it’s because of all the delegators used in the WebApp class.

 extend Forwardable
 def_delegators :@response_body, :<<, 
   :print, :printf, :putc, :puts, :write

 def_delegator :@request_header, :each, :each_request_header
 def_delegator :@request_header, :[], :get_request_header

 def_delegator :@request, :request_method, :request_method
 def_delegator :@request, :server_name, :server_name
 def_delegator :@request, :server_port, :server_port
 def_delegator :@request, :script_name, :script_name
 def_delegator :@request, :path_info, :path_info
 def_delegator :@request, :query_string, :query_string
 def_delegator :@request, :server_protocol, :server_protocol
 def_delegator :@request, :remote_addr, :remote_addr
 def_delegator :@request, :content_type, :request_content_type

 def_delegator :@response_header, :set, :set_header
 def_delegator :@response_header, :add, :add_header
 def_delegator :@response_header, :remove, :remove_header
 def_delegator :@response_header, :clear, :clear_header
 def_delegator :@response_header, :has?, :has_header?
 def_delegator :@response_header, :[], :get_header
 def_delegator :@response_header, :each, :each_header

WebApp doesn’t require the CGI module, so be sure to require it yourself if you need the encoding methods and such. (via del.icio.us)

Read: Holy Great CGI In Heaven!

Topic: Rails Grand Opening Previous Topic   Next Topic Topic: 5.gets David Heinemeier Hansson

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use