title: Conditionally updating cookie expiry time in nginx to find the idle time
body: <p>I'm trying to implement a solution to identify if there was an idle time of <code>X</code> minutes between two requests.</p>
  <p>For this, I'm planning to use the following approach.</p>
  <ol>
  <li>Initially, set a cookie from the application side. The expiry time of this cookie is set to <code>X</code> minutes.</li>
  <li>Whenever there is a request, in <code>nginx</code>, I will check if the cookie expiry time is passed or the cookie is available.</li>
  <li>If the cookie is available, and not expired, I will update the expiry time again with <code>X</code> minutes. Otherwise, delete the cookie.</li>
  <li>On the server-side, I can check the availability of the cookie and if available, I can conclude the previous request was within <code>X</code> minutes.</li>
  </ol>
  <p>To implement this solution, I will need some code snippets as below.</p>
  <pre><code>if cookie-exists and cookie.expirytime &gt; currentTime
    Set-Cookie: MY_COOKIE=SOMEVAL; Max-Age=X*60; Secure; HttpOnly
  else
    Drop-Cookie MY_COOKIE
  endif
  </code></pre>
  <p>How can I implement this condition check and cookie modification in nginx? Is it possible to do without <code>lua</code>?</p>
  <p>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.</p>