Class: Webmachine::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/webmachine/response.rb

Overview

Represents an HTTP response from Webmachine.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

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

Returns The response body

Returns:

  • (String, #each)

    The response body



11
12
13
# File 'lib/webmachine/response.rb', line 11

def body
  @body
end

- (Fixnum) code

Returns The HTTP status code of the response

Returns:

  • (Fixnum)

    The HTTP status code of the response



8
9
10
# File 'lib/webmachine/response.rb', line 8

def code
  @code
end

- (Symbol) end_state

Returns When an error has occurred, the last state the FSM was in

Returns:

  • (Symbol)

    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

Returns The error message when responding with an error code

Returns:

  • (String)

    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)

Returns Response headers that will be sent to the client

Returns:

  • (Hash)

    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?

Returns Whether the response is a redirect

Returns:

  • (true, false)

    Whether the response is a redirect



14
15
16
# File 'lib/webmachine/response.rb', line 14

def redirect
  @redirect
end

- (Array) trace (readonly)

Returns the list of states that were traversed

Returns:

  • (Array)

    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.

Parameters:

  • location (String, URI) (defaults to: nil)

    the target of the redirection



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