Class: Web2Go::CGIResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/Web2Go/CGIResponse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cgi) ⇒ CGIResponse

Returns a new instance of CGIResponse.



9
10
11
12
13
# File 'lib/Web2Go/CGIResponse.rb', line 9

def initialize(cgi)
  @cgi = cgi
  @content_type = 'text/html'
  @redirect = nil
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



7
8
9
# File 'lib/Web2Go/CGIResponse.rb', line 7

def content_type
  @content_type
end

Instance Method Details



46
47
48
49
50
51
52
# File 'lib/Web2Go/CGIResponse.rb', line 46

def add_cookie(name,value,domain=nil,path=nil,expires=nil)
  cookie = CGI::Cookie.new(name,value)
  cookie.expires = expires unless expires.nil?
  cookie.domain  = domain unless domain.nil?
  cookie.path    = path unless path.nil?
  set_cookie(cookie)
end

#add_cookies(cookies) ⇒ Object



54
55
56
57
58
# File 'lib/Web2Go/CGIResponse.rb', line 54

def add_cookies(cookies)
  #      cookies.each do |cookie|
  #        set_cookie(cookie)
  #      end
end

#body=(content) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/Web2Go/CGIResponse.rb', line 19

def body=(content)
  options = Hash.new
  options['type'] = @content_type

  if @cgi.cookies.length > 0 then
    options['cookie'] = @cgi.cookies
  end
  if !@redirect.nil? then
    options['Status'] = '302 Moved' 
    options[ 'location'] = @redirect
  end


  @cgi.out(options) do 
    content
  end

end

#cookiesObject



42
43
44
# File 'lib/Web2Go/CGIResponse.rb', line 42

def cookies
  @cgi.cookies
end

#redirect_to=(redirect_url) ⇒ Object



15
16
17
# File 'lib/Web2Go/CGIResponse.rb', line 15

def redirect_to=(redirect_url)
  @redirect = redirect_url
end


38
39
40
# File 'lib/Web2Go/CGIResponse.rb', line 38

def set_cookie(cookie)
  @cgi.cookies[cookie.name] = cookie
end