WEBrick - 嵌入式HTTP服务器程序库


未知
跨平台
Ruby

软件简介

WEBrick 是Ruby中内嵌的HTTP服务器程序库

下面是一个调用 WEBrick 实现最简单的 HTTP 服务器的代码:

#!/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