lib/http/broker.rb in rsence-2.1.6 vs lib/http/broker.rb in rsence-2.1.7

- old
+ new

@@ -22,31 +22,32 @@ # Broker sets up Rack and routes requests to the proper request processing instance. class Broker # This method is called from Rack. # @param [Hash] env is the Rack environment. - # @return [Array(Number, Hash, String)] Rack-style response status, header, body + # @return [Array(Number, Hash, Array)] Rack-style response status, header, body def call( env ) sleep @@ping_sim if @@ping_sim unless @@transporter.online? puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} -- Server busy." headers = { 'Retry-After' => '2', 'Content-Type' => 'text/plain', 'Refresh' => "2; #{env['REQUEST_URI']}", 'Content-Length' => '4' } - return [ 503, headers, 'BUSY' ] + return [ 503, headers, ['BUSY'] ] end request = Request.new(env) response = Response.new request_method = request.request_method.downcase dispatcher = dispatcher_class.new( request, response ) dispatcher.send( request_method ) content_type = dispatcher.content_type - response.header['Content-Length'] = response.body.length.to_s unless response.header.has_key?('Content-Length') - return [response.status, response.header, response.body] + response_body = response.body + response.header['Content-Length'] = response.body_bytes unless response.header.has_key?('Content-Length') + return [response.status, response.header, response_body] end # Returns a dynamically created "REST Dispatcher" kind of class that has # request and response as instance variables and the rest of the Broker # class as the superclass. It calls the method according to the http method. Called from {#call} @@ -119,10 +120,10 @@ def not_found puts "/404: #{@request.fullpath.inspect}" if RSence.args[:verbose] @response.status = 404 err404 = '<html><head><title>404 - Page Not Found</title></head><body>404 - Page Not Found</body></html>' @response['Content-Type'] = 'text/html; charset=UTF-8' - @response['Content-Length'] = err404.length.to_s + @response['Content-Length'] = err404.bytesize.to_s @response.body = err404 end # Routes POST requests to {Transporter#servlet} def post