Module: Nitro::Response

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

Overview

Override the default Response implementation to include methods useful for testing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#response_cookiesObject

The Response cookies.



17
18
19
# File 'lib/nitro/cgi/response.rb', line 17

def response_cookies
  @response_cookies
end

#response_headersObject

The Response headers.



13
14
15
# File 'lib/nitro/cgi/response.rb', line 13

def response_headers
  @response_headers
end

#statusObject

The Response status.



9
10
11
# File 'lib/nitro/cgi/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/nitro/cgi/response.rb', line 40

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

#content_typeObject

Return the content type for this response.



21
22
23
# File 'lib/nitro/cgi/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/nitro/cgi/response.rb', line 27

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

#redirect?Boolean

Returns:

  • (Boolean)


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

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

#redirect_urlObject



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

def redirect_url
  @response_headers['location']
end


32
33
34
35
# File 'lib/nitro/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/nitro/test/context.rb', line 20

def status_ok?
  @status == 200
end