提交 8603bc06 编写于 作者: S Steve Klabnik

Add propery docs to ActionDispatch::Response [ci skip]

After some discussion on Twitter with @skud, the documentation on ActionDispatch::Response is
a bit sparse. This class is useful when you're writing tests, as often you want to assert various
things about the response that's coming back. Better docs would make this easier for people new
to testing in Rails.

I only added some descriptions for various properties that were defined, and mostly just a sentence
or two. Most of these things are familliar if you're working with HTTP, but some words is better
than no words at all.

Hopefully further commits will fix up things that aren't just documentation.
上级 e43a99e2
......@@ -31,10 +31,17 @@ module ActionDispatch # :nodoc:
# end
# end
class Response
attr_accessor :request, :header
# The request that the response is responding to.
attr_accessor :request
# The HTTP status code.
attr_reader :status
attr_writer :sending_file
# Get and set headers for this response.
attr_accessor :header
alias_method :headers=, :header=
alias_method :headers, :header
......@@ -49,9 +56,12 @@ class Response
# If a character set has been defined for this response (see charset=) then
# the character set information will also be included in the content type
# information.
attr_accessor :charset
attr_reader :content_type
# The charset of the response. HTML wants to know the encoding of the
# content you're giving them, so we need to send that along.
attr_accessor :charset
CONTENT_TYPE = "Content-Type".freeze
SET_COOKIE = "Set-Cookie".freeze
LOCATION = "Location".freeze
......@@ -93,6 +103,7 @@ def closed?
end
end
# The underlying body, as a streamable object.
attr_reader :stream
def initialize(status = 200, header = {}, body = [])
......@@ -142,6 +153,7 @@ def status=(status)
@status = Rack::Utils.status_code(status)
end
# Sets the HTTP content type.
def content_type=(content_type)
@content_type = content_type.to_s
end
......@@ -216,11 +228,13 @@ def delete_cookie(key, value={})
::Rack::Utils.delete_cookie_header!(header, key, value)
end
# The location header we'll be responding with.
def location
headers[LOCATION]
end
alias_method :redirect_url, :location
# Sets the location header we'll be responding with.
def location=(url)
headers[LOCATION] = url
end
......@@ -229,11 +243,13 @@ def close
stream.close if stream.respond_to?(:close)
end
# Turns the Response into a Rack-compatible array of the status, headers,
# and body.
def to_a
rack_response @status, @header.to_hash
end
alias prepare! to_a
alias to_ary to_a # For implicit splat on 1.9.2
alias to_ary to_a
# Returns the response cookies, converted to a Hash of (name => value) pairs
#
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册