diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-08 11:56:40 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-08 16:14:46 -0700 |
commit | 25791b46dc48bec4375a8953d9b2def52761e237 (patch) | |
tree | d5e321f000fd9647aa4456ccddda45fb7605e84d /actionpack | |
parent | f9ff4e591ec7052f3f95f61885877fc09e6b77e8 (diff) | |
download | rails-25791b46dc48bec4375a8953d9b2def52761e237.tar.gz rails-25791b46dc48bec4375a8953d9b2def52761e237.tar.bz2 rails-25791b46dc48bec4375a8953d9b2def52761e237.zip |
pull content type parsing in to a method
we'll use this method later to lazily parse content type headers.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 4aee489912..e841db77b6 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -136,20 +136,28 @@ module ActionDispatch # :nodoc: @committed = false @sending = false @sent = false - @content_type = nil - @charset = self.class.default_charset - if content_type = self[CONTENT_TYPE] - type, charset = content_type.split(/;\s*charset=/) - @content_type = Mime::Type.lookup(type) - @charset = charset || self.class.default_charset - end + content_type = parse_content_type self[CONTENT_TYPE] + @content_type = content_type.mime_type + @charset = content_type.charset prepare_cache_control! yield self if block_given? end + ContentTypeHeader = Struct.new :mime_type, :charset + + def parse_content_type(content_type) + if content_type + type, charset = content_type.split(/;\s*charset=/) + ContentTypeHeader.new(Mime::Type.lookup(type), + charset || self.class.default_charset) + else + ContentTypeHeader.new(nil, self.class.default_charset) + end + end + def have_header?(key); headers.key? key; end def get_header(key); headers[key]; end def set_header(key, v); headers[key] = v; end |