
Table of contents:
WEBrick is a Ruby library program to build HTTP servers.
WEBrick has been bundled as a standard library since Ruby-1.8.0. Our development and maintenance base was moved to The Repository of Ruby. Note that this release is for the users of Ruby-1.6.
webrick-1.3.1.tar.gz (Changes)
The repository | Snapshot tarball | Snapshot ZIP archive
In addition, Anonymous CVS is also available:
$ cvs -d :pserver:anonymous@cvs.webrick.org:/home/ipr/ncvs login
(Logging in to anonymous@cvs.webrick.org)
CVS password: (just hit Enter key)
$ cvs -z4 -d :pserver:anonymous@cvs.webrick.org:/home/ipr/ncvs co webrick
#!/usr/local/bin/ruby
require 'webrick'
s = WEBrick::GenericServer.new( :Port => 2000 )
trap("INT"){ s.shutdown }
s.start{|sock|
sock.print(Time.now.to_s + "\r\n")
}
or
#!/usr/local/bin/ruby
require 'webrick'
class DaytimeServer < WEBrick::GenericServer
def run(sock)
sock.print(Time.now.to_s + "\r\n")
end
end
s = DaytimeServer.new( :Port => 2000 )
trap("INT"){ s.shutdown }
s.start
#!/usr/local/bin/ruby
require 'webrick'
include WEBrick
s = HTTPServer.new(
:Port => 2000,
:DocumentRoot => Dir::pwd + "/htdocs"
)
## mount subdirectories
s.mount("/ipr", HTTPServlet::FileHandler, "/proj/ipr/public_html")
s.mount("/~gotoyuzo",
HTTPServlet::FileHandler, "/home/gotoyuzo/public_html",
true) #<= allow to show directory index.
trap("INT"){ s.shutdown }
s.start
Note: This program requires Ruby/OpenSSL.
#!/usr/local/bin/ruby
require 'webrick'
require 'webrick/https'
s = WEBrick::HTTPServer.new(
:Port => 2000,
:DocumentRoot => Dir::pwd + "/htdocs",
:SSLEnable => true,
:SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE,
:SSLCertName => [ ["C","JP"], ["O","WEBrick.Org"], ["CN", "WWW"] ]
)
trap("INT"){ s.shutdown }
s.start
#!/usr/local/bin/ruby
require 'webrick'
include WEBrick
s = HTTPServer.new( :Port => 2000 )
# HTTPServer#mount(path, servletclass)
# When a request referring "/hello" is received,
# the HTTPServer get an instance of servletclass
# and then call a method named do_"a HTTP method".
class HelloServlet < HTTPServlet::AbstractServlet
def do_GET(req, res)
res.body = "<HTML>hello, world.</HTML>"
res['Content-Type'] = "text/html"
end
end
s.mount("/hello", HelloServlet)
# HTTPServer#mount_proc(path){|req, res| ...}
# You can mount also a block by `mount_proc'.
# This block is called when GET or POST.
s.mount_proc("/hello/again"){|req, res|
res.body = "<HTML>hello (again)</HTML>"
res['Content-Type'] = "text/html"
}
trap("INT"){ s.shutdown }
s.start
#!/usr/local/bin/ruby
require 'webrick/httpproxy'
s = WEBrick::HTTPProxyServer.new(
:Port => 2020,
:RequestCallback => Proc.new{|req,res|
puts "-"*70
puts req.request_line, req.raw_header
puts "-"*70
}
)
trap("INT"){ s.shutdown }
s.start
<URL:mailto:webricken@notwork.org> (in English) and <URL:mailto:webrickja@notwork.org> (in Japanese) have been set up for a purpose to talk about WEBrick.
To subscribe this list, please send the following phrase
subscribe Your-First-Name Your-Last-Name
in the mail body (not subject) to the address
<URL:mailto:webricken-ctl@notwork.org> (for webricken) or
<URL:mailto:webrickja-ctl@notwork.org> (for webrickja).
IPR -- Internet Programming with Ruby -- writers <ipr-feedback@notwork.org>
WEBrick is Copyright (c) 2002 Internet Programming with Ruby writers. It is free software, and may be redistributed under the terms specified in the COPYING file of the Ruby distribution.
WEBrick is provided by the writers and contributers ``as is'' and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the writer or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of WEBrick, even if advised of the possibility of such damage.