diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index <HASH>..<HASH> 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -348,6 +348,7 @@ module ActionDispatch # :nodoc:
       return if committed?
       assign_default_content_type_and_charset!
       handle_conditional_get!
+      handle_no_content!
     end
 
     def before_sending
@@ -405,10 +406,15 @@ module ActionDispatch # :nodoc:
       end
     end
 
+    def handle_no_content!
+      if NO_CONTENT_CODES.include?(@status)
+        @header.delete CONTENT_TYPE
+        @header.delete 'Content-Length'
+      end
+    end
+
     def rack_response(status, header)
       if NO_CONTENT_CODES.include?(status)
-        header.delete CONTENT_TYPE
-        header.delete 'Content-Length'
         [status, header, []]
       else
         [status, header, RackBody.new(self)]
mutate headers before committing the response

We should not mutate headers after the response has been committed.