From 48729e9ac7c033b0a50e27869e7c388240592e2b Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Thu, 25 Oct 2007 21:06:05 -0700 Subject: [PATCH] using Rack's Response to leverage it's code --- lib/sinatra/context.rb | 19 ++++++++++--------- lib/sinatra/dispatcher.rb | 6 +----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/sinatra/context.rb b/lib/sinatra/context.rb index 87190ee..8b2523b 100644 --- a/lib/sinatra/context.rb +++ b/lib/sinatra/context.rb @@ -5,19 +5,20 @@ module Sinatra class EventContext cattr_accessor :logger - attr_reader :request + attr_reader :request, :response include Sinatra::Renderer def initialize(request) #:nodoc: @request = request - @headers = {} + @response = Rack::Response.new + @response.body = nil end # Sets or returns the status def status(value = nil) - @status = value if value - @status || 200 + @response.status = value if value + @response.status || 200 end # Sets or returns the body @@ -30,9 +31,9 @@ module Sinatra # both are the same # def body(value = nil, &block) - @body = value if value - @body = block.call if block - @body + @response.body = value if value + @response.body = block.call if block + @response.body end # Renders an exception to +body+ and sets status to 500 @@ -56,8 +57,8 @@ module Sinatra # # Whatever blows your hair back def headers(value = nil) - @headers.merge!(value) if value - @headers + @response.headers.merge!(value) if value + @response.headers end alias :header :headers diff --git a/lib/sinatra/dispatcher.rb b/lib/sinatra/dispatcher.rb index f7dbca1..aedee46 100644 --- a/lib/sinatra/dispatcher.rb +++ b/lib/sinatra/dispatcher.rb @@ -3,10 +3,6 @@ module Sinatra class Dispatcher cattr_accessor :logger - - def default_headers - { 'Content-Type' => 'text/html' } - end def call(env) Loader.reload! if Options.environment == :development @@ -19,7 +15,7 @@ module Sinatra ) result = event.attend(@request) - [result.status, default_headers.merge(result.headers), result.body] + result.response.to_a end end -- 2.11.4.GIT