1- iHelpers = require (" KnownUserImplementationHelpers" )
2- knownUser = require (" KnownUser" )
3- utils = require (" Utils" )
1+ local iHelpers = require (" KnownUserImplementationHelpers" )
2+ local knownUser = require (" KnownUser" )
3+ local utils = require (" Utils" )
44
55local aHandler = {}
66
@@ -9,10 +9,10 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
99 assert (secretKey ~= nil , " secretKey invalid" )
1010 assert (config ~= nil , " config invalid" )
1111 assert (isIntegrationConfig ~= nil , " isIntegrationConfig invalid" )
12- assert (request_rec ~= nil , " request_rec invalid" )
13-
12+ assert (request_rec ~= nil , " request_rec invalid" )
13+
1414 -- Implement required helpers
15- -- ********************************************************************************
15+ -- ********************************************************************************
1616 iHelpers .system .getConnectorName = function ()
1717 return apache2 .version
1818 end
@@ -21,72 +21,72 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
2121 local json = require (" json" )
2222 return json .parse (jsonStr )
2323 end
24-
24+
2525 iHelpers .hash .hmac_sha256_encode = function (message , key )
2626 local sha2 = require (" sha2" )
2727 return sha2 .hmac (sha2 .sha256 , key , message )
2828 end
29-
29+
3030 iHelpers .request .getHeader = function (name )
3131 return request_rec .headers_in [name ]
3232 end
33-
33+
3434 iHelpers .request .getUnescapedCookieValue = function (name )
35- -- Alternative to request_rec:getcookie method,
35+ -- Alternative to request_rec:getcookie method,
3636 -- which fails if client sends a Cookie header with multiple entries with same name/key.
37- local function getCookieValue (name )
38- local function split (inputstr , sep )
39- sep = sep or ' %s' local t = {}
40- for field ,s in string.gmatch (inputstr , " ([^" .. sep .. " ]*)(" .. sep .. " ?)" ) do
41- table.insert (t ,field )
42- if s == " " then
43- return t
44- end
45- end
37+ local function getCookieValue (_name )
38+ local function split (inputstr , sep )
39+ sep = sep or ' %s' local t = {}
40+ for field ,s in string.gmatch (inputstr , " ([^" .. sep .. " ]*)(" .. sep .. " ?)" ) do
41+ table.insert (t ,field )
42+ if s == " " then
43+ return t
44+ end
45+ end
4646 end
47-
48- if (name == nil ) then
47+
48+ if (_name == nil ) then
4949 return nil
5050 end
5151
5252 local cookieHeader = request_rec .headers_in [" Cookie" ]
53-
53+
5454 if (cookieHeader == nil ) then
5555 return nil
5656 end
57-
57+
5858 local cookieHeaderParts = split (cookieHeader , " ;" )
59-
59+
6060 if (cookieHeaderParts == nil ) then
6161 return nil
6262 end
63-
63+
6464 -- Translate name to pattern so it will work correctly in string.find
65- -- ex. translate 'QueueITAccepted-SDFrts345E-V3_event1' to 'QueueITAccepted--SDFrts345E--V3_event1='
66- name = name :gsub (" -" , " --" ) .. " ="
67-
68- for k , v in pairs (cookieHeaderParts ) do
69- startIndex , endIndex = string.find (v , name )
70-
65+ -- ex. translate 'QueueITAccepted-SDFrts345E-V3_event1' to 'QueueITAccepted--SDFrts345E--V3_event1='
66+ _name = _name :gsub (" -" , " --" ) .. " ="
67+
68+ for _ , v in pairs (cookieHeaderParts ) do
69+ local _ , endIndex = string.find (v , _name )
70+
7171 if (endIndex ~= nil ) then
7272 return v :sub (endIndex + 1 )
7373 end
7474 end
7575 end
76-
76+
7777 local cookieValue = getCookieValue (name )
78-
78+
7979 if (cookieValue ~= nil ) then
8080 cookieValue = utils .urlDecode (cookieValue )
8181 end
8282
8383 return cookieValue
8484 end
85-
85+
8686 iHelpers .request .getUserHostAddress = function ()
8787 return request_rec .useragent_ip
8888 end
89-
89+
9090 -- Implementation is not using built in r:setcookie method
9191 -- because we want to support Apache version < 2.4.12
9292 -- where there is bug in that specific method
@@ -98,51 +98,50 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
9898 if (domain == nil ) then
9999 domain = " "
100100 end
101-
101+
102102 if (value == nil ) then
103103 value = " "
104104 end
105-
105+
106106 value = utils .urlEncode (value )
107107
108108 local expire_text = ' '
109109 if expire ~= nil and type (expire ) == " number" and expire > 0 then
110110 expire_text = ' ; Expires=' .. os.date (" !%a, %d %b %Y %H:%M:%S GMT" , expire )
111111 end
112112
113- request_rec .err_headers_out [" Set-Cookie" ] = name .. ' =' .. value
113+ request_rec .err_headers_out [" Set-Cookie" ] = name .. ' =' .. value
114114 .. expire_text
115- .. (domain ~= " " and ' ; Domain=' .. domain or ' ' )
115+ .. (domain ~= " " and ' ; Domain=' .. domain or ' ' )
116116 .. (iHelpers .response .cookieOptions .httpOnly and ' ; HttpOnly' or ' ' )
117117 .. (iHelpers .response .cookieOptions .secure and ' ; Secure' or ' ' )
118- .. (iHelpers .response .cookieOptions .sameSite and ' ; SameSite=' .. iHelpers .response .cookieOptions .sameSite or ' ' )
119118 .. ' ; Path=/;'
120-
119+
121120 end
122121 -- ********************************************************************************
123122 -- END Implement required helpers
124123
125124 local queueitToken = request_rec :parseargs ()[" queueittoken" ]
126125 local fullUrl = iHelpers .request .getAbsoluteUri ()
127- local currentUrlWithoutQueueitToken = fullUrl :gsub (" ([\\ %?%&])(" .. knownUser .QUEUEIT_TOKEN_KEY .. " =[^&]*)" , " " )
126+ local currentUrlWithoutQueueitToken = fullUrl :gsub (" ([\\ %?%&])(" .. knownUser .QUEUEIT_TOKEN_KEY .. " =[^&]*)" , " " )
128127
129- local validationResult = nil
128+ local validationResult
130129 if (isIntegrationConfig ) then
131130 validationResult = knownUser .validateRequestByIntegrationConfig (currentUrlWithoutQueueitToken , queueitToken , config , customerId , secretKey )
132131 else
133132 validationResult = knownUser .resolveQueueRequestByLocalConfig (currentUrlWithoutQueueitToken , queueitToken , config , customerId , secretKey )
134133 end
135-
134+
136135 if (validationResult :doRedirect ()) then
137136 -- Adding no cache headers to prevent browsers to cache requests
138137 request_rec .err_headers_out [" Cache-Control" ] = " no-cache, no-store, must-revalidate, max-age=0"
139138 request_rec .err_headers_out [" Pragma" ] = " no-cache"
140139 request_rec .err_headers_out [" Expires" ] = " Fri, 01 Jan 1990 00:00:00 GMT"
141140 -- end
142-
141+
143142 if (validationResult .isAjaxResult ) then
144143 request_rec .err_headers_out [validationResult .getAjaxQueueRedirectHeaderKey ()] = validationResult :getAjaxRedirectUrl ()
145- else
144+ else
146145 request_rec .err_headers_out [" Location" ] = validationResult .redirectUrl
147146 return apache2 .HTTP_MOVED_TEMPORARILY
148147 end
@@ -153,7 +152,7 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
153152 return apache2 .HTTP_MOVED_TEMPORARILY
154153 end
155154 end
156-
155+
157156 return apache2 .DECLINED
158157end
159158
0 commit comments