Class: WEBrick::HTTPServlet::ProcHandler

Inherits:
AbstractServlet show all
Defined in:
lib/webrick/httpservlet/prochandler.rb

Overview

Mounts a proc at a path that accepts a request and response.

Instead of mounting this servlet with WEBrick::HTTPServer#mount use WEBrick::HTTPServer#mount_proc:

server.mount_proc '/' do |req, res|
  res.body = 'it worked!'
  res.status = 200
end

Instance Method Summary collapse

Methods inherited from AbstractServlet

#do_HEAD, #do_OPTIONS, get_instance, #service

Constructor Details

#initialize(proc) ⇒ ProcHandler

Returns a new instance of ProcHandler.



34
35
36
# File 'lib/webrick/httpservlet/prochandler.rb', line 34

def initialize(proc)
  @proc = proc
end

Instance Method Details

#do_GET(request, response) ⇒ Object Also known as: do_POST, do_PUT



38
39
40
# File 'lib/webrick/httpservlet/prochandler.rb', line 38

def do_GET(request, response)
  @proc.call(request, response)
end

#get_instance(server, *options) ⇒ Object

:stopdoc:



30
31
32
# File 'lib/webrick/httpservlet/prochandler.rb', line 30

def get_instance(server, *options)
  self
end