Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

httpd.rb (See related posts)

// Simple ruby webrick server

require 'webrick'

# The :AccessLog configuration takes an array.
# Each element of the array should be
# a two-element array where the first element
# is the stream (or anything responding to <<)  and
# the second element is the access log format.
# Please see webrick/accesslog.rb for available formats.

access_log_stream = File.open('C:\\Documents and Settings\\madann\\My Documents\\access.log', 'w')
access_log = [ [ access_log_stream, WEBrick::AccessLog::COMBINED_LOG_FORMAT ] ]

DocumentRoot = 'C:\\Documents and Settings\\madann\\My Documents\\Public_html\\';
HTTPPort = 8008

begin
   d = Dir.open(DocumentRoot)
rescue
   puts "Creating Documentroot"
   mkdir DocumentRoot
end

class DownloadHandler < WEBrick::HTTPServlet::AbstractServlet
    def do_get(req,resp)
        p "req : ",req
        p "resp : ",resp
    end

    def go_post(req,resp)
        resp
    end
end


s = WEBrick::HTTPServer.new(
  :Port             => HTTPPort,
  :DocumentRoot     => DocumentRoot,
  :FancyIndexing    => true
  #:Logger          => WEBrick::Log.new('download.log'),
  #:AccessLog       => access_log
)

s.mount("/cgi-bin",
        WEBrick::HTTPServlet::FileHandler,
        "C:\\Documents and Settings\\madann\\My Documents\\Public_html\\cgi-bin\\",
        {:FancyIndexing=>true})

trap("INT"){ s.shutdown }
s.start

You need to create an account or log in to post comments to this site.


Related Posts