| 98 | } |
| 99 | |
| 100 | func getOrSetKey(ctx *context.Context) string { |
| 101 | if key := GetKey(ctx); key != "" { |
| 102 | return key |
| 103 | } |
| 104 | |
| 105 | // Note: by-default the rules(ruleset pkg) |
| 106 | // explicitly ignores the cache handler |
| 107 | // execution on authenticated requests |
| 108 | // and immediately runs the next handler: |
| 109 | // if !h.rule.Claim(ctx) ...see `Handler` method. |
| 110 | // So the below two lines are useless, |
| 111 | // however we add it for cases |
| 112 | // that the end-developer messedup with the rules |
| 113 | // and by accident allow authenticated cached results. |
| 114 | username, password, _ := ctx.Request().BasicAuth() |
| 115 | authPart := username + strings.Repeat("*", len(password)) |
| 116 | |
| 117 | key := ctx.Method() + authPart |
| 118 | |
| 119 | u := ctx.Request().URL |
| 120 | if !u.IsAbs() { |
| 121 | key += ctx.Scheme() + ctx.Host() |
| 122 | } |
| 123 | key += u.String() |
| 124 | |
| 125 | SetKey(ctx, key) |
| 126 | return key |
| 127 | } |
| 128 | |
| 129 | func (h *Handler) ServeHTTP(ctx *context.Context) { |
| 130 | // check for pre-cache validators, if at least one of them return false |