Class: Webmachine::Response
- Inherits:
-
Object
- Object
- Webmachine::Response
- Defined in:
- lib/webmachine/response.rb
Overview
Represents an HTTP response from Webmachine.
Instance Attribute Summary (collapse)
-
- (String, #each) body
The response body.
-
- (Fixnum) code
The HTTP status code of the response.
-
- (Symbol) end_state
When an error has occurred, the last state the FSM was in.
-
- (String) error
The error message when responding with an error code.
-
- (Hash) headers
readonly
Response headers that will be sent to the client.
-
- (true, false) redirect
(also: #is_redirect?)
Whether the response is a redirect.
-
- (Array) trace
readonly
The list of states that were traversed.
Instance Method Summary (collapse)
-
- (Object) do_redirect(location = nil)
Indicate that the response should be a redirect.
-
- (Response) initialize
constructor
Creates a new Response object with the appropriate defaults.
Constructor Details
- (Response) initialize
Creates a new Response object with the appropriate defaults.
28 29 30 31 32 33 |
# File 'lib/webmachine/response.rb', line 28 def initialize @headers = {} @trace = [] self.code = 200 self.redirect = false end |
Instance Attribute Details
- (String, #each) body
The response body
11 12 13 |
# File 'lib/webmachine/response.rb', line 11 def body @body end |
- (Fixnum) code
The HTTP status code of the response
8 9 10 |
# File 'lib/webmachine/response.rb', line 8 def code @code end |
- (Symbol) end_state
When an error has occurred, the last state the FSM was in
21 22 23 |
# File 'lib/webmachine/response.rb', line 21 def end_state @end_state end |
- (String) error
The error message when responding with an error code
25 26 27 |
# File 'lib/webmachine/response.rb', line 25 def error @error end |
- (Hash) headers (readonly)
Response headers that will be sent to the client
5 6 7 |
# File 'lib/webmachine/response.rb', line 5 def headers @headers end |
- (true, false) redirect Also known as: is_redirect?
Whether the response is a redirect
14 15 16 |
# File 'lib/webmachine/response.rb', line 14 def redirect @redirect end |
- (Array) trace (readonly)
The list of states that were traversed
17 18 19 |
# File 'lib/webmachine/response.rb', line 17 def trace @trace end |
Instance Method Details
- (Object) do_redirect(location = nil)
Indicate that the response should be a redirect. This is only used when processing a POST request in Callbacks#process_post to indicate that the client should request another resource using GET. Either pass the URI of the target resource, or manually set the Location header using #headers.
41 42 43 44 |
# File 'lib/webmachine/response.rb', line 41 def do_redirect(location=nil) headers['Location'] = location.to_s if location self.redirect = true end |