0
-module ActionController
0
- class AbstractResponse #:nodoc:
0
+module ActionController # :nodoc:
0
+ # Represents an HTTP response generated by a controller action. One can use an
0
+ # ActionController::AbstractResponse object to retrieve the current state of the
0
+ # response, or customize the response. An AbstractResponse object can either
0
+ # represent a "real" HTTP response (i.e. one that is meant to be sent back to the
0
+ # web browser) or a test response (i.e. one that is generated from integration
0
+ # tests). See CgiResponse and TestResponse, respectively.
0
+ # AbstractResponse is mostly a Ruby on Rails framework implement detail, and should
0
+ # never be used directly in controllers. Controllers should use the methods defined
0
+ # in ActionController::Base instead. For example, if you want to set the HTTP
0
+ # response's content MIME type, then use ActionControllerBase#headers instead of
0
+ # AbstractResponse#headers.
0
+ # Nevertheless, integration tests may want to inspect controller responses in more
0
+ # detail, and that's when AbstractResponse can be useful for application developers.
0
+ # Integration test methods such as ActionController::Integration::Session#get and
0
+ # ActionController::Integration::Session#post return objects of type TestResponse
0
+ # (which are of course also of type AbstractResponse).
0
+ # For example, the following demo integration "test" prints the body of the
0
+ # controller response to the console:
0
+ # class DemoControllerTest < ActionController::IntegrationTest
0
+ # def test_print_root_path_to_console
0
+ class AbstractResponse
0
DEFAULT_HEADERS = { "Cache-Control" => "no-cache" }
0
- attr_accessor :body, :headers, :session, :cookies, :assigns, :template, :redirected_to, :redirected_to_method_params, :layout
0
+ # The body content (e.g. HTML) of the response, as a String.
0
+ # The headers of the response, as a Hash. It maps header names to header values.
0
+ attr_accessor :headers
0
+ attr_accessor :session, :cookies, :assigns, :template, :redirected_to, :redirected_to_method_params, :layout
0
@body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
0
+ # Sets the HTTP response's content MIME type. For example, in the controller
0
+ # you could write this:
0
+ # response.content_type = "text/plain"
0
+ # If a character set has been defined for this response (see charset=) then
0
+ # the character set information will also be included in the content type
0
def content_type=(mime_type)
0
self.headers["Content-Type"] = charset ? "#{mime_type}; charset=#{charset}" : mime_type
0
+ # Returns the response's content MIME type, or nil if content type has been set.
0
content_type = String(headers["Content-Type"] || headers["type"]).split(";")[0]
0
content_type.blank? ? nil : content_type
0
@@ -73,4 +115,4 @@ module ActionController
0
self.headers["Content-Length"] = body.size unless body.respond_to?(:call)
0
\ No newline at end of file
Comments
No one has commented yet.