Class: Web2Go::CGIRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cgi) ⇒ CGIRequest

Returns a new instance of CGIRequest.


29
30
31
32
33
34
# File 'lib/Web2Go/CGIRequest.rb', line 29

def initialize(cgi)
  @cgi = cgi
  @server_variable = cgi.my_env
  @params = @cgi.params
  @user = nil
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params


26
27
28
# File 'lib/Web2Go/CGIRequest.rb', line 26

def params
  @params
end

#server_variableObject (readonly)

Returns the value of attribute server_variable


27
28
29
# File 'lib/Web2Go/CGIRequest.rb', line 27

def server_variable
  @server_variable
end

Instance Method Details

#authenticated?Boolean Also known as: authenticated

Returns:

  • (Boolean)

78
79
80
# File 'lib/Web2Go/CGIRequest.rb', line 78

def authenticated?
    !@cgi.auth_type.nil? && !@cgi.auth_type.empty?
end

105
106
107
108
109
110
111
# File 'lib/Web2Go/CGIRequest.rb', line 105

def cookie(name)
  if @cgi.cookies.has_key?(name) then
    return  @cgi.cookies[name]
  else
    return nil
  end
end

#cookiesObject


113
114
115
# File 'lib/Web2Go/CGIRequest.rb', line 113

def cookies
  @cgi.cookies
end

#hostObject


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/Web2Go/CGIRequest.rb', line 44

def host
  if @server_variable.has_key?('HTTP_X_FORWARDED_HOST') then
    host = @server_variable['HTTP_X_FORWARDED_HOST']
  else
    host = @cgi.server_name
  end
  if host =~ /^([^:]*):/ then
    host = $1
  end
  host 
end

#parameter(name, default_value = nil) ⇒ Object


88
89
90
91
92
93
94
95
# File 'lib/Web2Go/CGIRequest.rb', line 88

def parameter(name,default_value=nil)
  value = @params[name]
  if value.nil? || value.length < 1 then
    return default_value
  else
    return value[0]
  end
end

#pathObject


40
41
42
# File 'lib/Web2Go/CGIRequest.rb', line 40

def path
  @cgi.path_info
end

#portObject


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/Web2Go/CGIRequest.rb', line 56

def port
  if @server_variable.has_key?('HTTP_X_FORWARDED_HOST') then
    host = @server_variable['HTTP_X_FORWARDED_HOST']
    if host =~ /:(\d+)/ then
      $1
    else
      '80' 
    end
  else
    @cgi.server_port
  end
end

#query_stringObject


74
75
76
# File 'lib/Web2Go/CGIRequest.rb', line 74

def query_string
  @cgi.query_string
end

#request_methodObject


84
85
86
# File 'lib/Web2Go/CGIRequest.rb', line 84

def request_method
    @cgi.request_method
end

#script_nameObject


36
37
38
# File 'lib/Web2Go/CGIRequest.rb', line 36

def script_name
  @cgi.script_name
end

#uploaded_file(name, pos = 0) ⇒ Object


97
98
99
100
101
102
103
# File 'lib/Web2Go/CGIRequest.rb', line 97

def uploaded_file(name,pos=0)
  file = @params[name]
  if !file.nil? then
    return CGIFile.new(file[pos])
  end
  nil
end

#userObject


69
70
71
72
# File 'lib/Web2Go/CGIRequest.rb', line 69

def user
  @user ||= find_user
  @user
end