diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-24 10:33:25 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-24 13:54:42 -0700 |
commit | fcf5e178dd6384cb5f9e99c0026ba958e426a03f (patch) | |
tree | ce090f8d2af0da0b0a05a068ad2cca57072cbb68 /actionpack/lib/action_dispatch/http/response.rb | |
parent | a2448e74b9de544dd8b3fef7f0da0a91140af492 (diff) | |
download | rails-fcf5e178dd6384cb5f9e99c0026ba958e426a03f.tar.gz rails-fcf5e178dd6384cb5f9e99c0026ba958e426a03f.tar.bz2 rails-fcf5e178dd6384cb5f9e99c0026ba958e426a03f.zip |
move the Header hash to the super class
I want to move the header hash to the super request object in order to
consolidate behavior. We should be switching out buffering strategies
rather than header strategies since things like "mutating headers after
send" is an error in both cases (buffering vs streaming).
Diffstat (limited to 'actionpack/lib/action_dispatch/http/response.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index de3ca7d095..85d9c3be00 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -32,6 +32,29 @@ module ActionDispatch # :nodoc: # end # end class Response + class Header < DelegateClass(Hash) # :nodoc: + def initialize(response, header) + @response = response + super(header) + end + + def []=(k,v) + if @response.committed? + raise ActionDispatch::IllegalStateError, 'header already sent' + end + + super + end + + def merge(other) + self.class.new @response, __getobj__.merge(other) + end + + def to_hash + __getobj__.dup + end + end + # The request that the response is responding to. attr_accessor :request @@ -118,7 +141,7 @@ module ActionDispatch # :nodoc: def initialize(status = 200, header = {}, body = []) super() - @header = header + @header = Header.new(self, header) self.body, self.status = body, status |