Ejemplo
net/http go1.26.5: Show that `http.Client.Timeout` is enforced while reading a slow response body.
Muestra verificada para golang net/http go1.26.5: Show that `http.Client.Timeout` is enforced while reading a slow response body. El contrato se ejecutó en…
sha256:a5d71aedbea662543b6d6b4b60bce0ccd1b8876c606797a1bbab8655f25ddf1f
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 2
- Claves de firma que lo compilaron
- 2
Entorno declarado
go linux x64 go go go
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-16 |
| go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-18 |
Caso
HOW- Objetivo
- Show that `http.Client.Timeout` is enforced while reading a slow response body.
- Paquetes
- Símbolos
-
- Client.Timeout
- Entorno
- go
- Creado
- 2026-08-16T12:04:37Z
Contrato
- A request with a short `Client.Timeout` can get headers immediately yet still fail with a timeout while reading a slow body, proving the deadline covers more than setup.
Archivos
- NOTES.md
- client_timeout_test.go
- csx.json
- go.mod
Código fuente
search_known_solution for `pkg:golang/net/http@go1.26.5` + `Client.Timeout` returned a miss, so this uses a fresh proof.
The wrong expectation fails because the timeout still aborts mid-body reads (as `io.ReadAll` returns a deadline error) even though headers can arrive within the timeout.
package codesamplex
import (
"context"
"errors"
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestClientTimeoutLimitsResponseBodyRead(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
if _, err := w.Write([]byte("ok")); err != nil {
t.Error(err)
return
}
if f, ok := w.(http.Flusher); ok {
f.Flush()
}
time.Sleep(100 * time.Millisecond)
_, err := w.Write([]byte("too late"))
if err != nil {
t.Error(err)
return
}
}))
defer srv.Close()
client := &http.Client{
Timeout: 50 * time.Millisecond,
}
resp, err := client.Get(srv.URL)
if err != nil {
t.Fatalf("unexpected error before reading body: %v", err)
}
defer resp.Body.Close()
_, err = io.ReadAll(resp.Body)
if err == nil {
t.Fatal("expected timeout while reading body, got nil")
}
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("expected context deadline exceeded, got %v", err)
}
}
{"case":{"believed":"A common model expectation is that once headers arrive, a `http.Client` timeout no longer applies, so long response bodies can be read indefinitely.","caseId":"case:sha256:8a3b9795afd5fed47a451d4a013163fc7764b661cf0e78c579edb91221b7c212","contract":["A request with a short `Client.Timeout` can get headers immediately yet still fail with a timeout while reading a slow body, proving the deadline covers more than setup."],"goal":"Show that `http.Client.Timeout` is enforced while reading a slow response body.","kind":"HOW","packages":["pkg:golang/net/http@go1.26.5"],"schemaVersion":1,"symbols":["Client.Timeout"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","ecosystem":"golang","executionContext":"go","language":"go","os":"linux","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/net/http@go1.26.5"],"schemaVersion":1,"symbols":["Client.Timeout"],"verifierAdapter":"golang@1"}
module codesamplex
go 1.26