public
Rubygem
Fork of bmizerany/sinatra
Description: Classy web-development dressed in a DSL
Homepage: http://sinatrarb.com
Clone URL: git://github.com/adamwiggins/sinatra.git
:accept option sets content-type header
adamwiggins (author)
Mon Jun 09 00:41:45 -0700 2008
commit  8a99bd7ef181aca2f35a9df6bea18d512ebdfd39
tree    27e3b28dc74c9ccc52a683478c60a23fcaae9594
parent  cfcf7863a865337ea29c764db5a192bf46f50e29
...
95
96
97
98
 
99
100
101
...
179
180
181
182
 
 
183
184
185
...
188
189
190
191
 
192
193
194
...
202
203
204
205
 
206
207
208
...
213
214
215
216
 
217
218
219
...
1233
1234
1235
 
1236
1237
1238
...
95
96
97
 
98
99
100
101
...
179
180
181
 
182
183
184
185
186
...
189
190
191
 
192
193
194
195
...
203
204
205
 
206
207
208
209
...
214
215
216
 
217
218
219
220
...
1234
1235
1236
1237
1238
1239
1240
0
@@ -95,7 +95,7 @@ module Sinatra
0
   class NotFound < RuntimeError; end
0
   class ServerError < RuntimeError; end
0
 
0
-  Result = Struct.new(:block, :params, :status) unless defined?(Result)
0
+  Result = Struct.new(:block, :params, :status, :content_type) unless defined?(Result)
0
 
0
   def options
0
     application.options
0
@@ -179,7 +179,8 @@ module Sinatra
0
         return unless host === request.host
0
       end
0
       if accept = options[:accept]
0
-        return unless request.accept.include? lookup_mime(accept)
0
+        accept = lookup_mime(accept)
0
+        return unless request.accept.include? accept
0
       end
0
       return unless pattern =~ request.path_info.squeeze('/')
0
       params.merge!(param_keys.zip($~.captures.map(&:from_param)).to_hash)
0
@@ -188,7 +189,7 @@ module Sinatra
0
         params.delete_if { |k, v| k =~ /^_splat_\d+$/ }
0
         params["splat"] = splats
0
       end
0
-      Result.new(block, params, 200)
0
+      Result.new(block, params, 200, accept)
0
     end
0
     
0
   end
0
@@ -202,7 +203,7 @@ module Sinatra
0
     end
0
     
0
     def invoke(request)
0
-      Result.new(block, {}, 404)
0
+      Result.new(block, {}, 404, nil)
0
     end
0
     
0
   end
0
@@ -213,7 +214,7 @@ module Sinatra
0
       return unless File.file?(
0
         Sinatra.application.options.public + request.path_info.http_unescape
0
       )
0
-      Result.new(block, {}, 200)
0
+      Result.new(block, {}, 200, nil)
0
     end
0
     
0
     def block
0
@@ -1233,6 +1234,7 @@ module Sinatra
0
       result = lookup(request)
0
       context = EventContext.new(request, Rack::Response.new, result.params)
0
       context.status(result.status)
0
+      context.response.headers['Content-Type'] = result.content_type if result.content_type
0
       begin
0
         returned = run_safely do
0
           catch(:halt) do
...
224
225
226
 
227
228
229
...
224
225
226
227
228
229
230
0
@@ -224,6 +224,7 @@ context "Events in an app" do
0
     get_it '/', :env => { :accept => 'application/xml' }
0
     should.be.ok
0
     body.should.equal 'application/xml'
0
+    headers['Content-Type'].should.equal 'application/xml'
0
 
0
     get_it '/', :env => { :accept => 'text/html' }
0
     should.not.be.ok

Comments