In a Go 1.24 service (standard library only), there is an HTTP handler POST /reports that accepts JSON of the form {"name":"..."} and uses the Idempotency-Key header to protect against duplicate submissions. The in-memory storage must work correctly under concurrent requests; all access to shared state is performed under a single sync.Mutex, and there are no additional goroutines in this scenario.
Functional requirements:
Idempotency-Key, a new report is created and 201 Created is returned with JSON {"id":"...","name":"..."}.200 OK.Idempotency-Key header is missing or empty after strings.TrimSpace, the request is not considered idempotent: each such successful call must create a new report.400 Bad Request is returned and no record is created.You need to perform a code review of the PR diff and find defects in the after version. It is important to evaluate the actual contract of the code, not the desired design.
Reproduction steps:
http.NewServeMux() and register NewServer().HandleCreateReport on POST /reports.Idempotency-Key header, but with different bodies: two different ids and both 201 statuses are expected.Assumptions:
net/http mode; there is no special middleware for closing the body.Go 1.24, standard library, Linux/macOS/Windows; run in a normal net/http process without third-party dependencies and without background goroutines in this scenario. An HTTP/1.1 keep-alive client is assumed so that request-body leaks are observable at the connection level.
Use line comments to explain the problem, its impact, the fix and how to test it.