class Webmachine::Adapters::WEBrick::Server
WEBRick::HTTPServer that is run by the WEBrick
adapter.
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/webmachine/adapters/webrick.rb, line 30 def initialize(options) @application = options[:application] super(options) end
Public Instance Methods
service(wreq, wres)
click to toggle source
Handles a request
# File lib/webmachine/adapters/webrick.rb, line 36 def service(wreq, wres) header = Webmachine::Headers.new wreq.each { |k, v| header[k] = v } request = Webmachine::Request.new(wreq.request_method, wreq.request_uri, header, LazyRequestBody.new(wreq)) response = Webmachine::Response.new @application.dispatcher.dispatch(request, response) wres.status = response.code.to_i headers = response.headers.flattened.reject { |k, v| k == 'Set-Cookie' } headers.each { |k, v| wres[k] = v } cookies = [response.headers['Set-Cookie'] || []].flatten cookies.each { |c| wres.cookies << c } wres[SERVER] = [Webmachine::SERVER_STRING, wres.config[:ServerSoftware]].join(' ') case response.body when String wres.body << response.body when Enumerable wres.chunked = response.headers[TRANSFER_ENCODING] == 'chunked' response.body.each { |part| wres.body << part } else if response.body.respond_to?(:call) wres.chunked = true wres.body << response.body.call end end end