Module: Anorexic::HTTPEcho

Defined in:
lib/anorexic/handlers/http_echo.rb

Overview

this is a Handler stub class for an HTTP echo server.

Class Method Summary collapse

Class Method Details

.add_host(*args) ⇒ Object

does nothing - a simple stub as required from handlers


22
23
24
# File 'lib/anorexic/handlers/http_echo.rb', line 22

def add_host *args
  self
end

.add_route(*args) ⇒ Object

does nothing - a simple stub as required from handlers


17
18
19
# File 'lib/anorexic/handlers/http_echo.rb', line 17

def add_route *args
  self
end

.on_request(request) ⇒ Object

handles requests by printing out the parsed data. gets the `request` parameter from the HTTP protocol.


8
9
10
11
12
13
14
# File 'lib/anorexic/handlers/http_echo.rb', line 8

def on_request request
  response = HTTPResponse.new request, 200, {"content-type" => "text/plain"}, ["parsed as:\r\n", request.to_s]
  response.body.last << "\n\n params:"
  request.params.each {|k,v| response.body.last << "\n#{k}: #{v}"}
  response.send
  response.finish
end