使用 Webrick 开发一个基本的 HTTP 服务器

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require 'webrick'

class MyServlet < WEBrick::HTTPServlet::AbstractServlet
  def do_GET(request, response)
    response.status = 200
    response.content_type = "text/plain"
    response.body = "Hello, world!"
  end
end

server = WEBrick::HTTPServer.new(:Port => 1234)
server.mount "/", MyServlet
trap("INT"){ server.shutdown }
server.start