HashRequest mixes the request path into the body hash so the same Idempotency-Key cannot accidentally replay a cached response across different routes (e.g. reusing a key set on a reply to message A while replying to message B). The path is included on its own line before the body so the hash is una
(path string, body []byte)
| 118 | // Callers compute this once with the raw body bytes they already |
| 119 | // have and pass the result to Store.Claim. |
| 120 | func HashRequest(path string, body []byte) string { |
| 121 | h := sha256.New() |
| 122 | h.Write([]byte(path)) |
| 123 | h.Write([]byte{'\n'}) |
| 124 | h.Write(body) |
| 125 | return hex.EncodeToString(h.Sum(nil)) |
| 126 | } |
| 127 | |
| 128 | // Claim atomically reserves (userID, key) for the caller. The outcome |
| 129 | // determines what the HTTP layer should do next: |
no test coverage detected