forked from quic-go/quic-go
don't close the stream when the http.Request.Body is closed
On the server side, the http.Request is consumed by the HTTP handler. The HTTP handler may close the body (it doesn't have to though). In any case, closing the stream is the wrong thing to do, since that closes the write side of the stream. All we want to do is cancel the stream (if the EOF hasn't been read yet).
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user