http2: Use NO_ERROR instead of CANCEL when responding before the request is finished
This is required by RFC 7540 Section 8.1.
Bug pointed out by Mike Bishop.
Updates golang/go#19948
Change-Id: I58d4f499609fd493d33115f4e1f64caf4bcbbc03
Reviewed-on: https://go-review.googlesource.com/40630
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/http2/server.go b/http2/server.go
index 293f009..029ed95 100644
--- a/http2/server.go
+++ b/http2/server.go
@@ -1049,7 +1049,11 @@
// stateClosed after the RST_STREAM frame is
// written.
st.state = stateHalfClosedLocal
- sc.resetStream(streamError(st.id, ErrCodeCancel))
+ // Section 8.1: a server MAY request that the client abort
+ // transmission of a request without error by sending a
+ // RST_STREAM with an error code of NO_ERROR after sending
+ // a complete response.
+ sc.resetStream(streamError(st.id, ErrCodeNo))
case stateHalfClosedRemote:
sc.closeStream(st, errHandlerComplete)
}
diff --git a/http2/server_test.go b/http2/server_test.go
index 407fafc..591a0c2 100644
--- a/http2/server_test.go
+++ b/http2/server_test.go
@@ -2352,7 +2352,7 @@
// Sent when the a Handler closes while a client has
// indicated it's still sending DATA:
- st.wantRSTStream(1, ErrCodeCancel)
+ st.wantRSTStream(1, ErrCodeNo)
// Now the handler has ended, so it's ended its
// stream, but the client hasn't closed its side