From b89486eab0445fe7888969ce6ac8441ee998171c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 22 Sep 2010 22:59:19 +0100 Subject: [PATCH] Rework AMF controller's streaming output for rails 3 --- app/controllers/amf_controller.rb | 10 ++++++++-- config/initializers/mime_types.rb | 1 + test/functional/amf_controller_test.rb | 9 ++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index e776c8d8b..96d3602a9 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -66,7 +66,10 @@ class AmfController < ApplicationController end bodies=AMF.getint(req) # Read number of bodies - render :content_type => "application/x-amf", :text => proc { |response, output| + + self.status = :ok + self.content_type = Mime::AMF + self.response_body = proc { |response, output| a,b=bodies.divmod(256) output.write 0.chr+0.chr+0.chr+0.chr+a.chr+b.chr bodies.times do # Read each body @@ -114,7 +117,10 @@ class AmfController < ApplicationController end bodies=AMF.getint(req) # Read number of bodies - render :content_type => "application/x-amf", :text => proc { |response, output| + + self.status = :ok + self.content_type = Mime::AMF + self.response_body = proc { |response, output| a,b=bodies.divmod(256) output.write 0.chr+0.chr+0.chr+0.chr+a.chr+b.chr bodies.times do # Read each body diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 72aca7e44..c676f6e46 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -3,3 +3,4 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone +Mime::Type.register "application/x-amf", :amf diff --git a/test/functional/amf_controller_test.rb b/test/functional/amf_controller_test.rb index 2c76dfc9c..1ed8ebf48 100644 --- a/test/functional/amf_controller_test.rb +++ b/test/functional/amf_controller_test.rb @@ -577,13 +577,8 @@ class AmfControllerTest < ActionController::TestCase # The result is a hash of message_ref => data. # The attribute @amf_result is initialised to this hash. def amf_parse_response - if @response.body.class.to_s == 'Proc' - res = StringIO.new() - @response.body.call @response, res - req = StringIO.new(res.string) - else - req = StringIO.new(@response.body) - end + req = StringIO.new(@response.body) + req.read(2) # version # parse through any headers -- 2.43.2