I'm trying to implement a solution to identify if there was an idle time of X
minutes between two requests.
For this, I'm planning to use the following approach.
- Initially, set a cookie from the application side. The expiry time of this cookie is set to
X
minutes.
- Whenever there is a request, in
nginx
, I will check if the cookie expiry time is passed or the cookie is available.
- If the cookie is available, and not expired, I will update the expiry time again with
X
minutes. Otherwise, delete the cookie.
- On the server-side, I can check the availability of the cookie and if available, I can conclude the previous request was within
X
minutes.
To implement this solution, I will need some code snippets as below.
if cookie-exists and cookie.expirytime > currentTime
Set-Cookie: MY_COOKIE=SOMEVAL; Max-Age=X*60; Secure; HttpOnly
else
Drop-Cookie MY_COOKIE
endif
How can I implement this condition check and cookie modification in nginx? Is it possible to do without lua
?
I don't want to implement this logic on the application side because - there are multiple applications served through nginx and I want to keep the logic common to all. If the user is hitting any of the applications, the cookie should be updated.