Module: Raw::Response

Included in:
Context
Defined in:
lib/raw/test/context.rb,
lib/raw/context/response.rb

Overview

HTTP Response. This module is included in Context.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#response_cookiesObject

The Response cookies.



17
18
19
# File 'lib/raw/context/response.rb', line 17

def response_cookies
  @response_cookies
end

#response_headersObject

The Response headers.



13
14
15
# File 'lib/raw/context/response.rb', line 13

def response_headers
  @response_headers
end

#statusObject

The Response status.



9
10
11
# File 'lib/raw/context/response.rb', line 9

def status
  @status
end

Instance Method Details

Add a cookie to the response. Better use this method to avoid precreating the cookies array for every request.

Examples

add_cookie(‘nsid’, ‘gmosx’) add_cookie(Cookie.new(‘nsid’, ‘gmosx’)



40
41
42
43
44
45
46
# File 'lib/raw/context/response.rb', line 40

def add_cookie(cookie, value = nil)
  if value
    (@response_cookies ||= []) << Cookie.new(cookie, value)
  else 
    (@response_cookies ||= []) << cookie
  end
end

#bodyObject

Return the output buffer.



51
52
53
# File 'lib/raw/context/response.rb', line 51

def body
  @output_buffer
end

#content_typeObject

Return the content type for this response.



21
22
23
# File 'lib/raw/context/response.rb', line 21

def content_type
  @response_headers["Content-Type"]
end

#content_type=(ctype) ⇒ Object

Set the content type for this response.



27
28
29
# File 'lib/raw/context/response.rb', line 27

def content_type=(ctype)
  @response_headers["Content-Type"] = ctype
end

#redirect?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/raw/test/context.rb', line 24

def redirect?
  (300..399).include?(@status)
end

#redirect_uriObject



28
29
30
# File 'lib/raw/test/context.rb', line 28

def redirect_uri
  @response_headers['location']
end


32
33
34
35
# File 'lib/raw/test/context.rb', line 32

def response_cookie(name)
  return nil unless @response_cookies
  @response_cookies.find { |c| c.name == name }
end

#status_ok?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/raw/test/context.rb', line 20

def status_ok?
  @status == 200
end