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.



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

def initialize(proc)
  @proc = proc
end

Instance Method Details

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



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

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

#get_instance(server, *options) ⇒ Object

:stopdoc:



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

def get_instance(server, *options)
  self
end