@@ -186,12 +186,11 @@ function _M:extractContextVars(profile)
186186 return cachingObj
187187end
188188
189- function _M :validateRequest ()
189+ function _M :validateUserProfile ()
190190 -- ngx.var.authtoken needs to be set before calling this method
191191 local oauth_token = ngx .var .authtoken
192192 if oauth_token == nil or oauth_token == " " then
193- -- return self:exitFn(ngx.HTTP_BAD_REQUEST)
194- return self :exitFn (RESPONSES .P_MISSING_TOKEN .error_code , cjson .encode (RESPONSES .P_MISSING_TOKEN ))
193+ return RESPONSES .P_MISSING_TOKEN .error_code , cjson .encode (RESPONSES .P_MISSING_TOKEN )
195194 end
196195
197196 -- 1. try to get user's profile from the cache first ( local or redis cache )
@@ -205,9 +204,9 @@ function _M:validateRequest()
205204 end
206205 self :setContextProperties (self :getContextPropertiesObject (cachedUserProfile ))
207206 if ( self :isProfileValid (cachedUserProfile ) == true ) then
208- return self : exitFn ( ngx .HTTP_OK )
207+ return ngx .HTTP_OK
209208 else
210- return self : exitFn ( RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE ) )
209+ return RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE )
211210 end
212211 end
213212
@@ -223,9 +222,9 @@ function _M:validateRequest()
223222 self :storeProfileInCache (cacheLookupKey , cachingObj )
224223
225224 if ( self :isProfileValid (cachingObj ) == true ) then
226- return self : exitFn ( ngx .HTTP_OK )
225+ return ngx .HTTP_OK
227226 else
228- return self : exitFn ( RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE ) )
227+ return RESPONSES .INVALID_PROFILE .error_code , cjson .encode (RESPONSES .INVALID_PROFILE )
229228 end
230229 else
231230 ngx .log (ngx .WARN , " Could not decode /validate-user response:" .. tostring (res .body ) )
@@ -234,11 +233,15 @@ function _M:validateRequest()
234233 -- ngx.log(ngx.WARN, "Could not read /ims-profile. status=" .. res.status .. ".body=" .. res.body .. ". token=" .. ngx.var.authtoken)
235234 ngx .log (ngx .WARN , " Could not read /validate-user. status=" .. res .status .. " .body=" .. res .body )
236235 if ( res .status == ngx .HTTP_UNAUTHORIZED or res .status == ngx .HTTP_BAD_REQUEST ) then
237- return self : exitFn ( RESPONSES .NOT_ALLOWED .error_code , cjson .encode (RESPONSES .NOT_ALLOWED ) )
236+ return RESPONSES .NOT_ALLOWED .error_code , cjson .encode (RESPONSES .NOT_ALLOWED )
238237 end
239238 end
240239 -- ngx.log(ngx.WARN, "Error validating Profile for Token:" .. tostring(ngx.var.authtoken))
241- return self :exitFn (RESPONSES .P_UNKNOWN_ERROR .error_code , cjson .encode (RESPONSES .P_UNKNOWN_ERROR ))
240+ return RESPONSES .P_UNKNOWN_ERROR .error_code , cjson .encode (RESPONSES .P_UNKNOWN_ERROR )
241+ end
242+
243+ function _M :validateRequest ()
244+ return self :exitFn (self :validateUserProfile ())
242245end
243246
244247return _M
0 commit comments