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
14
# File 'lib/Web2Go/CGIResponse.rb', line 9

def initialize(cgi)
  @cgi = cgi
  @content_type = 'text/html'
  @redirect = nil
  @cookies = Hash.new
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



56
57
58
59
60
61
62
# File 'lib/Web2Go/CGIResponse.rb', line 56

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

#body=(content) ⇒ Object



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

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

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

end

#cookiesObject



52
53
54
# File 'lib/Web2Go/CGIResponse.rb', line 52

def cookies
  @cookies
end

#failedObject



38
39
40
41
42
43
44
45
# File 'lib/Web2Go/CGIResponse.rb', line 38

def failed
  options = Hash.new
  options['type'] = @content_type
  options['Status'] = '404 Not Found'
  @cgi.out(options) do 
    ""
  end
end

#redirect_to=(redirect_url) ⇒ Object



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

def redirect_to=(redirect_url)
  @redirect = redirect_url
end


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

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