Class: Webmachine::Adapters::Rack

Overview

A minimal “shim” adapter to allow Webmachine to interface with Rack. The
intention here is to allow Webmachine to run under Rack-compatible
web-servers, like unicorn and pow, and is not intended to allow Webmachine
to be “plugged in” to an existing Rack app as middleware.

To use this adapter, create a config.ru file and populate it like so:

require'webmachine/adapters/rack'# put your own Webmachine resources in another file:
require'my/resources'runMyApplication.adapter

Servers like pow and unicorn will read config.ru by default and it should
all “just work”.

And for development or testing your application can be run with Rack's
builtin Server identically to the Mongrel and WEBrick adapters with:

Instance Method Details

#call(env) ⇒ Object

# File 'lib/webmachine/adapters/rack.rb', line 55defcall(env)headers=Webmachine::Headers.from_cgi(env)rack_req=::Rack::Request.newenvrequest=Webmachine::Request.new(rack_req.request_method,URI.parse(rack_req.url),headers,RequestBody.new(rack_req))response=Webmachine::Response.newapplication.dispatcher.dispatch(request,response)response.headers['Server']=[Webmachine::SERVER_STRING,"Rack/#{::Rack.version}"].join("")rack_status=response.coderack_headers=response.headers.flattened("\n")rack_body=caseresponse.bodywhenString# Strings are enumerable in ruby 1.8
[response.body]elseifresponse.body.respond_to?(:call)Webmachine::ChunkedBody.new(Array(response.body.call))elsifresponse.body.respond_to?(:each)# This might be an IOEncoder with a Content-Length, which shouldn't be chunked.
ifresponse.headers["Transfer-Encoding"]=="chunked"Webmachine::ChunkedBody.new(response.body)elseresponse.bodyendelse[response.body.to_s]endendrack_res=RackResponse.new(rack_body,rack_status,rack_headers)rack_res.finishend