File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?php
22
3+ setcookie ('wordpress_logged_in_123123 ' , 'abcdefg ' );
4+
35header ('x-test: testing ' );
46
57echo 'hi ' ;
Original file line number Diff line number Diff line change 1+ package handlers
2+
3+ import (
4+ "net/http"
5+ "regexp"
6+
7+ "github.com/golevi/cache-handler/config"
8+ )
9+
10+ // Cookie compares the config cookie values against the ones sent by the request
11+ // and if one matches, we want to bypass the cache.
12+ func Cookie (c config.Config , w http.ResponseWriter , r * http.Request ) bool {
13+ // Loop through all the cookies from the request
14+ for _ , cookie := range r .Cookies () {
15+ // Loop through all the regexp cookie names from the config
16+ for _ , cc := range c .Cookie {
17+ // Compile the regexp
18+ rge := regexp .MustCompile (cc )
19+ // If we find a cookie, return true that we should bypass the cache.
20+ if rge .Find ([]byte (cookie .Name )) != nil {
21+ return true
22+ }
23+ }
24+ }
25+
26+ return false
27+ }
Original file line number Diff line number Diff line change @@ -258,6 +258,7 @@ func (c *Cache) Provision(ctx caddy.Context) error {
258258
259259 c .Deciders = append (c .Deciders , handlers .URI )
260260 c .Deciders = append (c .Deciders , handlers .Method )
261+ c .Deciders = append (c .Deciders , handlers .Cookie )
261262
262263 return nil
263264}
You can’t perform that action at this time.
0 commit comments