Score:0

Conditionally updating cookie expiry time in nginx to find the idle time

cn flag

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.

  1. Initially, set a cookie from the application side. The expiry time of this cookie is set to X minutes.
  2. Whenever there is a request, in nginx, I will check if the cookie expiry time is passed or the cookie is available.
  3. If the cookie is available, and not expired, I will update the expiry time again with X minutes. Otherwise, delete the cookie.
  4. 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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.