CodeSampleX

샘플

net/http go1.26.5: Prove that net/http mutates a gzip response at the client boundary instead of preserving raw transfer shape.

검증된 샘플 — golang net/http go1.26.5: Prove that net/http mutates a gzip response at the client boundary instead of preserving raw transfer shape. go 1.26 …

sha256:78e4711f9d506993f466ebedaae4f1c6636c420b765ce7576ba6a2b5a239991f

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 go linux x64 go go golang

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
Prove that net/http mutates a gzip response at the client boundary instead of preserving raw transfer shape.
패키지
심벌
  • http.Client
환경
go
생성일
2026-08-16T13:09:01Z

컨트랙트

  1. When a server writes a gzip-compressed body, a default http.Client request must return plain text bytes, not gzip bytes.
  2. The response seen by the caller must have Uncompressed set to true and lose Content-Encoding after decoding.

파일

  • NOTES.md
  • csx.json
  • go.mod
  • gzip_roundtrip_test.go

소스 아티팩트 내려받기 (tar.gz)

소스

NOTES.md
A prior cache lookup found net/http cases for timeout sample `case:sha256:8a3b9795afd5fed47a451d4a013163fc7764b661cf0e78c579edb91221b7c212` and ServeMux method-pattern sample `case:sha256:0d4b034698a0346c1a1a03f0dab522b49ea18f19b7ef59476dd07f92911c1b96`; this sample deliberately uses a different boundary trap: implicit gzip decoding in the `http.Client` response path.

On this environment, the wrong model expectation is that transport returns the encoded bytes and `Content-Encoding` metadata unchanged; that passes compile but fails the contract as a wrong model would predict gzip payload, while the real result is auto-decoded bytes with decoded metadata.
csx.json
{"case":{"believed":"A caller using a default http.Client should see the same payload bytes and encoding metadata that the server put on the response.","caseId":"case:sha256:4571ecad28f768631797459437c7c601d82486411426911c5f821ba35978b938","contract":["When a server writes a gzip-compressed body, a default http.Client request must return plain text bytes, not gzip bytes.","The response seen by the caller must have Uncompressed set to true and lose Content-Encoding after decoding."],"goal":"Prove that net/http mutates a gzip response at the client boundary instead of preserving raw transfer shape.","kind":"HOW","packages":["pkg:golang/net/http@go1.26.5"],"schemaVersion":1,"symbols":["http.Client"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","ecosystem":"golang","executionContext":"go","language":"go","os":"linux","packageManager":"golang","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/net/http@go1.26.5"],"schemaVersion":1,"symbols":["http.Client"],"verifierAdapter":"golang@1"}
go.mod
module github.com/example/http-boundary-sample

go 1.26

gzip_roundtrip_test.go
package main

import (
    "bytes"
    "compress/gzip"
    "io"
    "net/http"
    "net/http/httptest"
    "testing"
)

func TestHTTPClientAutoDecompressesGzipResponse(t *testing.T) {
    plain := []byte("answer=42")

    var gzPayload bytes.Buffer
    writer := gzip.NewWriter(&gzPayload)
    if _, err := writer.Write(plain); err != nil {
        t.Fatalf("gzip write failed: %v", err)
    }
    if err := writer.Close(); err != nil {
        t.Fatalf("gzip close failed: %v", err)
    }

    server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
        w.Header().Set("Content-Type", "text/plain")
        w.Header().Set("Content-Encoding", "gzip")
        _, _ = w.Write(gzPayload.Bytes())
    }))
    defer server.Close()

    response, err := http.Get(server.URL)
    if err != nil {
        t.Fatalf("request failed: %v", err)
    }
    defer response.Body.Close()

    body, err := io.ReadAll(response.Body)
    if err != nil {
        t.Fatalf("read body failed: %v", err)
    }

    if !bytes.Equal(body, plain) {
        t.Fatalf("expected decompressed body %q, got %q", plain, body)
    }
    if response.Uncompressed != true {
        t.Fatalf("expected Uncompressed=true on auto-decoded response")
    }
    if response.Header.Get("Content-Encoding") != "" {
        t.Fatalf("expected Content-Encoding to be stripped after auto-decoding, got %q", response.Header.Get("Content-Encoding"))
    }
}

오리진 시더

csx-seed