Ruby/Network/Webrick Web Server
Материал из Wiki.crossplatform.ru
access to request and response objects
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
find out what URL the user tried to access in his or her browser
require "webrick" class MyServlet < WEBrick::HTTPServlet::AbstractServlet def do_GET(request, response) response.status = 200 response.content_type = "text/plain" response.body = "You are trying to load #{request.path}" end end server = WEBrick::HTTPServer.new(:Port => 1234) server.mount "/", MyServlet trap("INT"){ server.shutdown } server.start
WEBrick is a Ruby library that makes it easy to build an HTTP server with Ruby
require "webrick" server = WEBrick::GenericServer.new(:Port => 1234) trap("INT"){ server.shutdown } server.start do |socket| socket.puts Time.now end