Sha256: 4e14160bf8e4cabcf6de3b50a3b542dbe0506b14b15cfda68bf481c3321fa36c

Contents?: true

Size: 1.56 KB

Versions: 18

Compression:

Stored size: 1.56 KB

Contents

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

  Copyright (C) 2005  Masao Mutoh

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

  $Id: http.rb,v 1.2 2006/02/20 12:35:06 mutoh Exp $
=end

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

if /mswin32/ =~ RUBY_PLATFORM
  interpreter = '.\ruby.bat'
else
  interpreter = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) +
 			       Config::CONFIG['EXEEXT']
end

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

18 entries across 18 versions & 1 rubygems

Version Path
gettext-1.10.0-mswin32 samples/cgi/http.rb
gettext-1.9.0-mswin32 samples/cgi/http.rb
gettext-1.8.0-mswin32 samples/cgi/http.rb
gettext-1.7.0-mswin32 samples/cgi/http.rb
gettext-1.6.0-mswin32 samples/cgi/http.rb
gettext-1.5.0-mswin32 samples/cgi/http.rb
gettext-1.4.0-mswin32 samples/cgi/http.rb
gettext-1.3.0-mswin32 samples/cgi/http.rb
gettext-1.2.0-mswin32 samples/cgi/http.rb
gettext-1.10.0 samples/cgi/http.rb
gettext-1.2.0 samples/cgi/http.rb
gettext-1.5.0 samples/cgi/http.rb
gettext-1.3.0 samples/cgi/http.rb
gettext-1.4.0 samples/cgi/http.rb
gettext-1.7.0 samples/cgi/http.rb
gettext-1.6.0 samples/cgi/http.rb
gettext-1.8.0 samples/cgi/http.rb
gettext-1.9.0 samples/cgi/http.rb