aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/live.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-25 16:34:06 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-25 16:34:06 -0700
commitd1b9a134cfc6ca543dab594f87e6b7c1ea0050f5 (patch)
tree0aeb1498d99c4e1528f2a6fc0bf2c0fa3d01f15f /actionpack/lib/action_controller/metal/live.rb
parent67b2841fbeb6db33dd78a95dd61329a8a56fc7c0 (diff)
downloadrails-d1b9a134cfc6ca543dab594f87e6b7c1ea0050f5.tar.gz
rails-d1b9a134cfc6ca543dab594f87e6b7c1ea0050f5.tar.bz2
rails-d1b9a134cfc6ca543dab594f87e6b7c1ea0050f5.zip
move response allocation to the class level
we don't need an instance to figure out what type of response to allocate. Later we'll pull this up the stack and pass the response object down
Diffstat (limited to 'actionpack/lib/action_controller/metal/live.rb')
-rw-r--r--actionpack/lib/action_controller/metal/live.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb
index 58150cd9a9..69583f8ab4 100644
--- a/actionpack/lib/action_controller/metal/live.rb
+++ b/actionpack/lib/action_controller/metal/live.rb
@@ -33,6 +33,20 @@ module ActionController
# the main thread. Make sure your actions are thread safe, and this shouldn't
# be a problem (don't share state across threads, etc).
module Live
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def make_response!(request)
+ if request.env["HTTP_VERSION"] == "HTTP/1.0"
+ super
+ else
+ Live::Response.new.tap do |res|
+ res.request = request
+ end
+ end
+ end
+ end
+
# This class provides the ability to write an SSE (Server Sent Event)
# to an IO stream. The class is initialized with a stream and can be used
# to either write a JSON string or an object which can be converted to JSON.
@@ -311,12 +325,7 @@ module ActionController
end
def set_response!(request)
- if request.env["HTTP_VERSION"] == "HTTP/1.0"
- super
- else
- @_response = Live::Response.new
- @_response.request = request
- end
+ @_response = self.class.make_response! request
end
end
end