Sha256: 8a16e991f5ab95efd8aa4a5b0ec3996060533d69eea63c53d19396b99e1f627b

Contents?: true

Size: 1.5 KB

Versions: 13

Compression:

Stored size: 1.5 KB

Contents

#! /usr/bin/env ruby
=begin
  http.rb - An WebServer for helloerb sample.

  Copyright (C) 2005-2008 Masao Mutoh

  You may redistribute it and/or modify it under the same
  license terms as Ruby.

  $Id: http.rb,v 1.3 2008/02/02 16:47:40 mutoh Exp $
=end

require 'webrick'
require 'cgi'
require 'rbconfig'

interpreter = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) +
 			       Config::CONFIG['EXEEXT']

srv = WEBrick::HTTPServer.new({:BindAddress => '127.0.0.1',
                               :Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
			       :CGIInterpreter => interpreter,
			      # :CGIInterpreter => "ruby -d",
			       :Port => 10080})

['INT', 'TERM'].each { |signal|
   trap(signal){ srv.shutdown} 
}

srv.mount("/", WEBrick::HTTPServlet::FileHandler, File.expand_path('.'))

srv.mount_proc("/src/") do |req, res|
  res.header["Content-Type"] = "text/html; charset=UTF-8"
  if req.query_string
    file = File.open(req.query_string).read
    res.body = %Q[<html>
                <head>
                  <title>View a source code</title>
                  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                  <link rel="stylesheet" type="text/css" href="/gettext.css" media="all">
                </head>
                <body><h1>#{req.query_string}</h1>
                <pre>#{CGI.escapeHTML(file)}</pre>
                <p><a href="/">Back</a></p>
                </body>
                </html>
                ]
  end
end

srv.start

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
experteer-gettext-2.0.4.1 samples/cgi/http.rb
experteer-gettext-2.0.4.2 samples/cgi/http.rb
experteer-gettext-2.0.4 samples/cgi/http.rb
grosser-gettext-2.0.0 samples/cgi/http.rb
gettext-1.92.0 samples/cgi/http.rb
gettext-1.90.0 samples/cgi/http.rb
gettext-1.91.0 samples/cgi/http.rb
gettext-2.0.1 samples/cgi/http.rb
gettext-2.0.2 samples/cgi/http.rb
gettext-2.0.0 samples/cgi/http.rb
gettext-1.93.0 samples/cgi/http.rb
gettext-2.0.4 samples/cgi/http.rb
gettext-2.0.3 samples/cgi/http.rb