Sha256: c1d1e1966df844bb8761862e61af397789ae4518ea7efc21617b171d283e92d8

Contents?: true

Size: 1.47 KB

Versions: 61

Compression:

Stored size: 1.47 KB

Contents

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

  Copyright (C) 2005-2009 Masao Mutoh

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

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

interpreter = File.join(::RbConfig::CONFIG['bindir'], ::RbConfig::CONFIG['ruby_install_name']) +
              ::RbConfig::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

61 entries across 61 versions & 1 rubygems

Version Path
gettext-3.3.0 samples/cgi/http.rb
gettext-3.2.9 samples/cgi/http.rb
gettext-3.2.8 samples/cgi/http.rb
gettext-3.2.7 samples/cgi/http.rb
gettext-3.2.6 samples/cgi/http.rb
gettext-3.2.5 samples/cgi/http.rb
gettext-3.2.4 samples/cgi/http.rb
gettext-3.2.3 samples/cgi/http.rb
gettext-3.2.2 samples/cgi/http.rb
gettext-3.2.1 samples/cgi/http.rb
gettext-3.2.0 samples/cgi/http.rb
gettext-3.1.9 samples/cgi/http.rb
gettext-3.1.8 samples/cgi/http.rb
gettext-3.1.7 samples/cgi/http.rb
gettext-3.1.6 samples/cgi/http.rb
gettext-3.1.5 samples/cgi/http.rb
gettext-3.1.4 samples/cgi/http.rb
gettext-3.1.3 samples/cgi/http.rb
gettext-3.1.2 samples/cgi/http.rb
gettext-3.1.1 samples/cgi/http.rb