title: Detect Set-Cookie expiration
body: <p>I want to be able to detect when a response from the backend contains this:</p>
  
  <p><code>testCookie="ASF@ED124312FASdf23er="; Version=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/; Secure</code></p>
  
  <p>What I want to detect is that the response is going to set the expiration date to <code>01 Jan 1970</code> for the cookie called <code>testCookie</code>.</p>
  
  <p>The challenge is in the fact that haproxy when using a fetch method to get a header, <a href="https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#7.3.6-res.hdr" rel="nofollow noreferrer">will consider commas as the delimiter for separate values.</a> and the alternative proposed, which is to use fhdr to fetch the complete header indeed works but will not enable you to filter for a specific <code>Set-Cookie</code> header via a regex filter or something, so you have to rely on a fixed index of the <code>Set-Cookie</code> header to be fetched....and that is not acceptable obviously.</p>
  
  <p>So, I have tried:</p>
  
  <h3>ACL with regex</h3>
  
  <p><code>acl is_expiration hdr_reg(Set-Cookie) &lt;enter_regex_here&gt;</code></p>
  
  <p>This has the downside that the comma in the expiration date will cause haproxy to parse that value in 2 separate parts so you can either match the first part which gives you the correct cookie identifier or the second part which has the expiration date.</p>
  
  <h3>Full Header with var and separate acl</h3>
  
  <p><code>http-response set-var(txn.temp_var) res.fhdr(Set-Cookie)
  acl is_expiration var(txn.temp_var) -m sub 01\ Jan\ 1970
  </code></p>
  
  <p>This will store the whole text in the Set-Cookie header in a temporary value and then I can do a substring match on that, or a regular expression but I still run into the problem of the comma and this is approach is error prone because it will take the first <code>Set-Cookie</code> header found or one found at a specific index I can specify.</p>
  
  <h3>Workaround</h3>
  
  <p>I could match by the Max-Age but if the server implementation changes and Expires and Max-Age switch places, I am screwed.</p>
  
  <p><code>acl is_expiration hdr_reg(Set-Cookie) testCookie.*Max-Age=0</code></p>
  
  <p>So.....heeeeelp!!!</p>