Class: TDiary::CGICompat

Inherits:
Object
  • Object
show all
Includes:
RequestExtension
Defined in:
lib/tdiary/cgi_compat.rb

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.

Direct Known Subclasses

RackCGI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestExtension

#https?, #mobile_agent?, #param, #remote_addr, #remote_user, #smartphone?, #static_assets?, #tdiary_base_url, #valid?

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
  # built eagerly so that a clone (Object#clone copies instance
  # variables by reference) shares the same params Hash, like a
  # cloned CGI instance does. Plugins may still rely on this.
  @params = request.cgi_params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



22
23
24
# File 'lib/tdiary/cgi_compat.rb', line 22

def params
  @params
end

#requestObject (readonly)

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_typeObject



72
73
74
# File 'lib/tdiary/cgi_compat.rb', line 72

def auth_type
  env_table['AUTH_TYPE']
end

#base_urlObject



109
110
111
# File 'lib/tdiary/cgi_compat.rb', line 109

def base_url
  tdiary_base_url
end

#cgi_cookiesObject



38
39
40
# File 'lib/tdiary/cgi_compat.rb', line 38

def cgi_cookies
  @request.cgi_cookies
end

#cgi_paramsObject

the stateful RequestExtension readers delegate to the wrapped request, so core code reading the request directly sees the same params Hash and the same hidden-referer state as plugins do through this facade



34
35
36
# File 'lib/tdiary/cgi_compat.rb', line 34

def cgi_params
  @request.cgi_params
end

#cookiesObject



50
51
52
53
54
# File 'lib/tdiary/cgi_compat.rb', line 50

def cookies
  # CGI::Cookie keeps the multi-value cookie behaviour (00default.rb
  # reads name and mail from the two values of the tdiary cookie)
  cgi_cookies
end

#envObject

the env of the wrapped request, for the stateless RequestExtension readers (remote_addr, https?, tdiary_base_url, ...)



26
27
28
# File 'lib/tdiary/cgi_compat.rb', line 26

def env
  @request.env
end

#env_tableObject



56
57
58
# File 'lib/tdiary/cgi_compat.rb', line 56

def env_table
  @request.env
end

#gateway_interfaceObject



76
77
78
# File 'lib/tdiary/cgi_compat.rb', line 76

def gateway_interface
  env_table['GATEWAY_INTERFACE']
end

#hide_referer!Object



42
43
44
# File 'lib/tdiary/cgi_compat.rb', line 42

def hide_referer!
  @request.hide_referer!
end

#redirect_urlObject



105
106
107
# File 'lib/tdiary/cgi_compat.rb', line 105

def redirect_url
  env_table['REDIRECT_URL']
end

#refererObject



46
47
48
# File 'lib/tdiary/cgi_compat.rb', line 46

def referer
  @request.referer
end

#request_methodObject



64
65
66
# File 'lib/tdiary/cgi_compat.rb', line 64

def request_method
  env_table['REQUEST_METHOD']
end

#request_uriObject

the URL helpers below come from the CGI patches that used to live in core_ext.rb



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/tdiary/cgi_compat.rb', line 90

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'] || ''
    # Workaround for IIS-style PATH_INFO ('/dir/script.cgi/path', not '/path')
    # See http://support.microsoft.com/kb/184320/
    _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_nameObject



68
69
70
# File 'lib/tdiary/cgi_compat.rb', line 68

def script_name
  env_table['SCRIPT_NAME']
end

#server_nameObject



80
81
82
# File 'lib/tdiary/cgi_compat.rb', line 80

def server_name
  env_table['SERVER_NAME']
end

#server_portObject



84
85
86
# File 'lib/tdiary/cgi_compat.rb', line 84

def server_port
  env_table['SERVER_PORT'].to_i
end

#user_agentObject



60
61
62
# File 'lib/tdiary/cgi_compat.rb', line 60

def user_agent
  env_table['HTTP_USER_AGENT']
end