= newClientServerTest(t, mode, HandlerFunc(test.handler))

			resp, err := cst.c.Get(cst.ts.URL)
			if err != nil {
				t.Fatalf("Get: %v", err)
			}
			if ct := resp.Header.Get("Content-Type"); ct != expected {
				t.Errorf("Content-Type = %q, want %q", ct, expected)
			}
			if want, got := resp.Header.Get("Content-Length"), fmt.Sprint(len(input)); want != got {
				t.Errorf("Content-Length = %q, want %q", want, got)
			}
			data, err := io.ReadAll(resp.Body)
			if err != nil {
				t.Errorf("reading body: %v", err)
			} else if !bytes.Equal(data, []byte(input)) {
				t.Errorf("data is %q, want %q", data, input)
			}
			resp.Body.Close()

		})

	}
}

func TestSniffWriteSize(t *testing.T) { run(t, testSniffWriteSize) }
func testSniffWriteSize(t *testing.T, mode testMode) {
	cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
		size, _ := strconv.Atoi(r.FormValue("size"))
		written, err := io.WriteString(w, strings.Repeat("a", size))
		if err != nil {
			t.Errorf("write of %d bytes: %v", size, err)
			return
		}
		if written != size {
			t.Errorf("write of %d bytes wrote %d bytes", size, written)
		}
	}))
	for _, size := range []int{0, 1, 200, 600, 999, 1000, 1023, 1024, 512 << 10, 1 << 20} {
		res, err := cst.c.Get(fmt.Sprintf("%s/?size=%d", cst.ts.URL, size))
		if err != nil {
			t.Fatalf("size %d: %v", size, err)
		}
		if _, err := io.Copy(io.Discard, res.Body); err != nil {
			t.Fatalf("size %d: io.Copy of body = %v", size, err)
		}
		if err := res.Body.Close(); err != nil {
			t.Fatalf("size %d: body Close = %v", size, err)
		}
	}
}
