WEBrick嵌入式HTTP服務器程序庫
WEBrick是Ruby中內(nèi)嵌的HTTP服務器程序庫
下面是一個調(diào)用 WEBrick 實現(xiàn)最簡單的 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
評論
圖片
表情
