transport: stop using http.CloseNotifier in handler server (#2697)
This commit is contained in:
@ -63,9 +63,6 @@ func NewServerHandlerTransport(w http.ResponseWriter, r *http.Request, stats sta
|
|||||||
if _, ok := w.(http.Flusher); !ok {
|
if _, ok := w.(http.Flusher); !ok {
|
||||||
return nil, errors.New("gRPC requires a ResponseWriter supporting http.Flusher")
|
return nil, errors.New("gRPC requires a ResponseWriter supporting http.Flusher")
|
||||||
}
|
}
|
||||||
if _, ok := w.(http.CloseNotifier); !ok {
|
|
||||||
return nil, errors.New("gRPC requires a ResponseWriter supporting http.CloseNotifier")
|
|
||||||
}
|
|
||||||
|
|
||||||
st := &serverHandlerTransport{
|
st := &serverHandlerTransport{
|
||||||
rw: w,
|
rw: w,
|
||||||
@ -308,19 +305,13 @@ func (ht *serverHandlerTransport) HandleStreams(startStream func(*Stream), trace
|
|||||||
ctx, cancel = context.WithCancel(ctx)
|
ctx, cancel = context.WithCancel(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// requestOver is closed when either the request's context is done
|
// requestOver is closed when the status has been written via WriteStatus.
|
||||||
// or the status has been written via WriteStatus.
|
|
||||||
requestOver := make(chan struct{})
|
requestOver := make(chan struct{})
|
||||||
|
|
||||||
// clientGone receives a single value if peer is gone, either
|
|
||||||
// because the underlying connection is dead or because the
|
|
||||||
// peer sends an http2 RST_STREAM.
|
|
||||||
clientGone := ht.rw.(http.CloseNotifier).CloseNotify()
|
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-requestOver:
|
case <-requestOver:
|
||||||
case <-ht.closedCh:
|
case <-ht.closedCh:
|
||||||
case <-clientGone:
|
case <-ht.req.Context().Done():
|
||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
ht.Close()
|
ht.Close()
|
||||||
|
@ -98,26 +98,6 @@ func TestHandlerTransport_NewServerHandlerTransport(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantErr: "gRPC requires a ResponseWriter supporting http.Flusher",
|
wantErr: "gRPC requires a ResponseWriter supporting http.Flusher",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "not closenotifier",
|
|
||||||
req: &http.Request{
|
|
||||||
ProtoMajor: 2,
|
|
||||||
Method: "POST",
|
|
||||||
Header: http.Header{
|
|
||||||
"Content-Type": {"application/grpc"},
|
|
||||||
},
|
|
||||||
RequestURI: "/service/foo.bar",
|
|
||||||
},
|
|
||||||
modrw: func(w http.ResponseWriter) http.ResponseWriter {
|
|
||||||
// Return w without its CloseNotify method
|
|
||||||
type onlyFlusher interface {
|
|
||||||
http.ResponseWriter
|
|
||||||
http.Flusher
|
|
||||||
}
|
|
||||||
return struct{ onlyFlusher }{w.(onlyFlusher)}
|
|
||||||
},
|
|
||||||
wantErr: "gRPC requires a ResponseWriter supporting http.CloseNotifier",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
req: &http.Request{
|
req: &http.Request{
|
||||||
|
Reference in New Issue
Block a user