diff --git a/http3/body.go b/http3/body.go index e0b19321..761d0783 100644 --- a/http3/body.go +++ b/http3/body.go @@ -11,8 +11,6 @@ import ( type body struct { str quic.Stream - isRequest bool - // only set for the http.Response // The channel is closed when the user is done with this response: // either when Read() errors, or when Close() is called. @@ -30,7 +28,6 @@ func newRequestBody(str quic.Stream, onFrameError func()) *body { return &body{ str: str, onFrameError: onFrameError, - isRequest: true, } } @@ -44,7 +41,7 @@ func newResponseBody(str quic.Stream, done chan<- struct{}, onFrameError func()) func (r *body) Read(b []byte) (int, error) { n, err := r.readImpl(b) - if err != nil && !r.isRequest { + if err != nil { r.requestDone() } return n, err @@ -86,7 +83,7 @@ func (r *body) readImpl(b []byte) (int, error) { } func (r *body) requestDone() { - if r.reqDoneClosed { + if r.reqDoneClosed || r.reqDone == nil { return } close(r.reqDone) @@ -94,11 +91,8 @@ func (r *body) requestDone() { } func (r *body) Close() error { - // quic.Stream.Close() closes the write side, not the read side - if r.isRequest { - return r.str.Close() - } r.requestDone() + // If the EOF was read, CancelRead() is a no-op. r.str.CancelRead(quic.ErrorCode(errorRequestCanceled)) return nil } diff --git a/http3/body_test.go b/http3/body_test.go index 17e90d7f..af731bd3 100644 --- a/http3/body_test.go +++ b/http3/body_test.go @@ -155,13 +155,6 @@ var _ = Describe("Body", func() { Expect(errorCbCalled).To(BeTrue()) }) - if bodyType == bodyTypeRequest { - It("closes requests", func() { - str.EXPECT().Close() - Expect(rb.Close()).To(Succeed()) - }) - } - if bodyType == bodyTypeResponse { It("closes the reqDone channel when Read errors", func() { buf.Write([]byte("invalid"))