From 25791b46dc48bec4375a8953d9b2def52761e237 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Tue, 8 Sep 2015 11:56:40 -0700
Subject: pull content type parsing in to a method

we'll use this method later to lazily parse content type headers.
---
 actionpack/lib/action_dispatch/http/response.rb | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

(limited to 'actionpack')

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
-- 
cgit v1.2.3