Class: TDiary::CGICompat
Overview
class CGICompat
provides the CGI compatible interface consumed by plugins as @cgi on
top of TDiary::Request. Behaviour is locked by the shared examples in
spec/support/cgi_compat_shared_examples.rb, which are also applied to
RackCGI, the subclass the dispatcher hands to plugins on the Rack path.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#mobile_agent?, #smartphone?
Constructor Details
#initialize(request) ⇒ CGICompat
Returns a new instance of CGICompat.
14
15
16
17
18
19
20
|
# File 'lib/tdiary/cgi_compat.rb', line 14
def initialize( request )
@request = request
@params = build_params
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
22
23
24
|
# File 'lib/tdiary/cgi_compat.rb', line 22
def params
@params
end
|
#request ⇒ Object
Returns the value of attribute request.
12
13
14
|
# File 'lib/tdiary/cgi_compat.rb', line 12
def request
@request
end
|
Instance Method Details
#auth_type ⇒ Object
62
63
64
|
# File 'lib/tdiary/cgi_compat.rb', line 62
def auth_type
env_table['AUTH_TYPE']
end
|
#base_url ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/tdiary/cgi_compat.rb', line 105
def base_url
return '' unless script_name
begin
script_dirname = script_name.empty? ? '' : File::dirname(script_name)
if https?
port = (server_port == 443) ? '' : ':' + server_port.to_s
"https://#{server_name}#{port}#{script_dirname}/"
else
port = (server_port == 80) ? '' : ':' + server_port.to_s
"http://#{server_name}#{port}#{script_dirname}/"
end.sub(%r|/+$|, '/')
rescue SecurityError
''
end
end
|
#cookies ⇒ Object
28
29
30
31
32
|
# File 'lib/tdiary/cgi_compat.rb', line 28
def cookies
@cookies ||= CGI::Cookie.parse( env_table['HTTP_COOKIE'] )
end
|
#env_table ⇒ Object
34
35
36
|
# File 'lib/tdiary/cgi_compat.rb', line 34
def env_table
@request.env
end
|
#gateway_interface ⇒ Object
66
67
68
|
# File 'lib/tdiary/cgi_compat.rb', line 66
def gateway_interface
env_table['GATEWAY_INTERFACE']
end
|
#https? ⇒ Boolean
the URL helpers below come from the CGI patches that used to live
in core_ext.rb
80
81
82
83
84
|
# File 'lib/tdiary/cgi_compat.rb', line 80
def https?
return true if env_table['HTTP_X_FORWARDED_PROTO'] == 'https'
return false if env_table['HTTPS'].nil? or /off/i =~ env_table['HTTPS'] or env_table['HTTPS'] == ''
true
end
|
#redirect_url ⇒ Object
101
102
103
|
# File 'lib/tdiary/cgi_compat.rb', line 101
def redirect_url
env_table['REDIRECT_URL']
end
|
#referer ⇒ Object
38
39
40
|
# File 'lib/tdiary/cgi_compat.rb', line 38
def referer
env_table['HTTP_REFERER']
end
|
#remote_addr ⇒ Object
46
47
48
|
# File 'lib/tdiary/cgi_compat.rb', line 46
def remote_addr
env_table['REMOTE_ADDR']
end
|
#remote_user ⇒ Object
58
59
60
|
# File 'lib/tdiary/cgi_compat.rb', line 58
def remote_user
env_table['REMOTE_USER']
end
|
#request_method ⇒ Object
50
51
52
|
# File 'lib/tdiary/cgi_compat.rb', line 50
def request_method
env_table['REQUEST_METHOD']
end
|
#request_uri ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/tdiary/cgi_compat.rb', line 86
def request_uri
_request_uri = env_table['REQUEST_URI']
_script_name = env_table['SCRIPT_NAME']
if !_request_uri || _request_uri == '' || _request_uri == _script_name then
_path_info = env_table['PATH_INFO'] || ''
_query_string = env_table['QUERY_STRING'] || ''
_request_uri = _path_info.include?(_script_name) ? '' : _script_name.dup
_request_uri << _path_info
_request_uri << '?' + _query_string if _query_string != ''
end
_request_uri
end
|
#script_name ⇒ Object
54
55
56
|
# File 'lib/tdiary/cgi_compat.rb', line 54
def script_name
env_table['SCRIPT_NAME']
end
|
#server_name ⇒ Object
70
71
72
|
# File 'lib/tdiary/cgi_compat.rb', line 70
def server_name
env_table['SERVER_NAME']
end
|
#server_port ⇒ Object
74
75
76
|
# File 'lib/tdiary/cgi_compat.rb', line 74
def server_port
env_table['SERVER_PORT'].to_i
end
|
#user_agent ⇒ Object
42
43
44
|
# File 'lib/tdiary/cgi_compat.rb', line 42
def user_agent
env_table['HTTP_USER_AGENT']
end
|
#valid?(param, idx = 0) ⇒ Boolean
24
25
26
|
# File 'lib/tdiary/cgi_compat.rb', line 24
def valid?( param, idx = 0 )
params[param] and params[param][idx] and params[param][idx].length > 0
end
|