From 9e72480ecceb93be7aae77a0255b12a95e7aad34 Mon Sep 17 00:00:00 2001 From: Matteo Pace Date: Sat, 3 Aug 2024 23:34:11 +0200 Subject: [PATCH] chore: port interceptor correction --- http/interceptor.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/http/interceptor.go b/http/interceptor.go index 06d765635..0fa9febab 100644 --- a/http/interceptor.go +++ b/http/interceptor.go @@ -83,7 +83,11 @@ func (i *rwInterceptor) Write(b []byte) (int, error) { // if there is an interruption it must be from at least phase 4 and hence // WriteHeader or Write should have been called and hence the status code // has been flushed to the delegated response writer. - return 0, nil + // + // We return the number of bytes as according to the interface io.Writer + // if we don't return an error, the number of bytes written is len(p). + // See https://pkg.go.dev/io#Writer + return len(b), nil } if !i.wroteHeader { @@ -102,7 +106,10 @@ func (i *rwInterceptor) Write(b []byte) (int, error) { i.overrideWriteHeader(obtainStatusCodeFromInterruptionOrDefault(it, i.statusCode)) // We only flush the status code after an interruption. i.flushWriteHeader() - return 0, nil + // We return the number of bytes as according to the interface io.Writer + // if we don't return an error, the number of bytes written is len(p). + // See https://pkg.go.dev/io#Writer + return len(b), nil } return n, err }