diff --git a/internal/http3/server.go b/internal/http3/server.go
index 6536eab..2501b19 100644
--- a/internal/http3/server.go
+++ b/internal/http3/server.go
@@ -414,11 +414,12 @@
// As a special case, we always want to save b to the buffer even when b is
// big if we had yet to write our header, so we can infer headers like
// "Content-Type" with as much information as possible.
+ initialBLen := len(b)
initialBufLen := len(rw.bb)
if !rw.wroteHeader || len(b) <= cap(rw.bb)-len(rw.bb) {
b = rw.bb.write(b)
if len(b) == 0 {
- return len(b), nil
+ return initialBLen, nil
}
}
@@ -430,13 +431,13 @@
// 3. Reset the current body buffer so it can be used again.
rw.writeHeaderLockedOnce()
if rw.cannotHaveBody {
- return len(b), nil
+ return initialBLen, nil
}
if n, err := rw.bw.write(rw.bb, b); err != nil {
return max(0, n-initialBufLen), err
}
rw.bb.discard()
- return len(b), nil
+ return initialBLen, nil
}
func (rw *responseWriter) Flush() {
diff --git a/internal/http3/server_test.go b/internal/http3/server_test.go
index 0583cf0..a56581b 100644
--- a/internal/http3/server_test.go
+++ b/internal/http3/server_test.go
@@ -755,7 +755,13 @@
ts := newTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
for n := 0; n < tt.bodyLen; n += tt.writeSize {
data := slices.Repeat([]byte("a"), min(tt.writeSize, tt.bodyLen-n))
- w.Write(data)
+ n, err := w.Write(data)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if n != len(data) {
+ t.Errorf("got %v bytes when writing in server handler, want %v", n, len(data))
+ }
if tt.flushes {
w.(http.Flusher).Flush()
}