lib/reel/rack/server.rb in reel-rack-0.0.1.pre vs lib/reel/rack/server.rb in reel-rack-0.0.1.pre2
- old
+ new
@@ -5,15 +5,21 @@
require 'rack'
module Reel
module Rack
class Server < Server
+ include Celluloid::Logger
+
attr_reader :app
+
def initialize(app, options)
raise ArgumentError, "no host given" unless options[:host]
raise ArgumentError, "no port given" unless options[:port]
+ info "A Reel good HTTP server! (Codename \"#{::Reel::CODENAME}\")"
+ info "Listening on http://#{options[:host]}:#{options[:port]}"
+
super(options[:host], options[:port], &method(:on_connection))
@app = app
end
def on_connection(connection)
@@ -33,15 +39,18 @@
"REMOTE_ADDR" => request.remote_addr
}.merge(convert_headers(request.headers))
status, headers, body = app.call ::Rack::MockRequest.env_for(request.url, options)
- if body.respond_to? :each
+ if body.respond_to?(:to_str)
+ request.respond status_symbol(status), headers, body.to_str
+ elsif body.respond_to?(:each)
request.respond status_symbol(status), headers.merge(:transfer_encoding => :chunked)
body.each { |chunk| request << chunk }
request.finish_response
else
- request.respond status_symbol(status), headers, body
+ Logger.error("don't know how to render: #{body.inspect}")
+ request.respond :internal_server_error, "An error occurred processing your request"
end
body.close if body.respond_to? :close
end