aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-07-29 17:55:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-07-29 21:43:05 -0700
commit06c9e176ca1b74e99bc258295bfbd8d2f2f33563 (patch)
tree91e30b7d53d158e43a0f444bf52cd8688d85516d /actionpack/lib
parent01b812672a3ef6f1032bfff5e818f1ad8957e378 (diff)
downloadrails-06c9e176ca1b74e99bc258295bfbd8d2f2f33563.tar.gz
rails-06c9e176ca1b74e99bc258295bfbd8d2f2f33563.tar.bz2
rails-06c9e176ca1b74e99bc258295bfbd8d2f2f33563.zip
raise exceptions on header set after response committed
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/live.rb21
-rw-r--r--actionpack/lib/action_dispatch.rb3
2 files changed, 24 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb
index aea00849d3..efeeefda9d 100644
--- a/actionpack/lib/action_controller/metal/live.rb
+++ b/actionpack/lib/action_controller/metal/live.rb
@@ -1,4 +1,5 @@
require 'action_dispatch/http/response'
+require 'delegate'
module ActionController
module Live
@@ -30,6 +31,26 @@ module ActionController
end
end
+ class Header < DelegateClass(Hash)
+ def initialize(response, header)
+ @response = response
+ super(header)
+ end
+
+ def []=(k,v)
+ if @response.committed?
+ raise ActionDispatch::IllegalStateError, 'header already sent'
+ end
+
+ super
+ end
+ end
+
+ def initialize(status = 200, header = {}, body = [])
+ header = Header.new self, header
+ super(status, header, body)
+ end
+
private
def build_buffer(response, body)
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index 1e4ac70f3d..c259b865cc 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/actionpack/lib/action_dispatch.rb
@@ -36,6 +36,9 @@ end
module ActionDispatch
extend ActiveSupport::Autoload
+ class IllegalStateError < StandardError
+ end
+
autoload_under 'http' do
autoload :Request
autoload :Response