Sha256: 35682d071b18ff38cff877d05c910d7d576ececa9adeedb347305d3c3fb660c1

Contents?: true

Size: 1.53 KB

Versions: 6

Compression:

Stored size: 1.53 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.1.1.1 2005/08/13 02:38:08 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,
			       :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

6 entries across 6 versions & 1 rubygems

Version Path
gettext-1.1.1-mswin32 samples/cgi/http.rb
gettext-1.1.0-mswin32 samples/cgi/http.rb
gettext-1.0.0-mswin32 samples/cgi/http.rb
gettext-1.0.0 samples/cgi/http.rb
gettext-1.1.0 samples/cgi/http.rb
gettext-1.1.1 samples/cgi/http.rb