From 62dc1bfaf4c27e689d8f35e17ca2614ab61826a4 Mon Sep 17 00:00:00 2001 From: Florian Reiterer Date: Tue, 2 Feb 2016 16:25:02 +0100 Subject: [PATCH] Cancel context when HTTP connection is closed --- .../examplepb/a_bit_of_everything.pb.gw.go | 88 ++++++++ examples/examplepb/echo_service.pb.gw.go | 16 ++ examples/examplepb/flow_combination.pb.gw.go | 208 ++++++++++++++++++ .../gengateway/template.go | 8 + 4 files changed, 320 insertions(+) diff --git a/examples/examplepb/a_bit_of_everything.pb.gw.go b/examples/examplepb/a_bit_of_everything.pb.gw.go index 66dc7399e00..4d3bbb091e6 100644 --- a/examples/examplepb/a_bit_of_everything.pb.gw.go +++ b/examples/examplepb/a_bit_of_everything.pb.gw.go @@ -434,6 +434,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se client := NewABitOfEverythingServiceClient(conn) mux.Handle("POST", pattern_ABitOfEverythingService_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_Create_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -445,6 +453,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("POST", pattern_ABitOfEverythingService_CreateBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_CreateBody_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -456,6 +472,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("POST", pattern_ABitOfEverythingService_BulkCreate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_BulkCreate_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -467,6 +491,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("GET", pattern_ABitOfEverythingService_Lookup_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_Lookup_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -478,6 +510,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("GET", pattern_ABitOfEverythingService_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_List_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -489,6 +529,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("PUT", pattern_ABitOfEverythingService_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_Update_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -500,6 +548,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("DELETE", pattern_ABitOfEverythingService_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_Delete_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -511,6 +567,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("GET", pattern_ABitOfEverythingService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_Echo_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -522,6 +586,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("POST", pattern_ABitOfEverythingService_Echo_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_Echo_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -533,6 +605,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("GET", pattern_ABitOfEverythingService_Echo_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_Echo_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -544,6 +624,14 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) mux.Handle("POST", pattern_ABitOfEverythingService_BulkEcho_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_ABitOfEverythingService_BulkEcho_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) diff --git a/examples/examplepb/echo_service.pb.gw.go b/examples/examplepb/echo_service.pb.gw.go index 8ab505b58aa..9927d88328f 100644 --- a/examples/examplepb/echo_service.pb.gw.go +++ b/examples/examplepb/echo_service.pb.gw.go @@ -94,6 +94,14 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn client := NewEchoServiceClient(conn) mux.Handle("POST", pattern_EchoService_Echo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_EchoService_Echo_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -105,6 +113,14 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn }) mux.Handle("POST", pattern_EchoService_EchoBody_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_EchoService_EchoBody_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) diff --git a/examples/examplepb/flow_combination.pb.gw.go b/examples/examplepb/flow_combination.pb.gw.go index 73ca8ed436e..a725b8e684d 100644 --- a/examples/examplepb/flow_combination.pb.gw.go +++ b/examples/examplepb/flow_combination.pb.gw.go @@ -814,6 +814,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, client := NewFlowCombinationClient(conn) mux.Handle("POST", pattern_FlowCombination_RpcEmptyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcEmptyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -825,6 +833,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcEmptyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcEmptyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -836,6 +852,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_StreamEmptyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_StreamEmptyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -847,6 +871,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_StreamEmptyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_StreamEmptyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -858,6 +890,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -869,6 +909,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyRpc_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -880,6 +928,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyRpc_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -891,6 +947,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_3, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyRpc_3(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -902,6 +966,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_4, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyRpc_4(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -913,6 +985,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_5, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyRpc_5(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -924,6 +1004,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyRpc_6, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyRpc_6(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -935,6 +1023,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathSingleNestedRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathSingleNestedRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -946,6 +1042,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathNestedRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -957,6 +1061,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathNestedRpc_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -968,6 +1080,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedRpc_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathNestedRpc_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -979,6 +1099,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -990,6 +1118,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyStream_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1001,6 +1137,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyStream_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1012,6 +1156,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_3, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyStream_3(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1023,6 +1175,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_4, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyStream_4(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1034,6 +1194,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_5, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyStream_5(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1045,6 +1213,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcBodyStream_6, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcBodyStream_6(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1056,6 +1232,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathSingleNestedStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathSingleNestedStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1067,6 +1251,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathNestedStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1078,6 +1270,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathNestedStream_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) @@ -1089,6 +1289,14 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, }) mux.Handle("POST", pattern_FlowCombination_RpcPathNestedStream_2, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_FlowCombination_RpcPathNestedStream_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err) diff --git a/protoc-gen-grpc-gateway/gengateway/template.go b/protoc-gen-grpc-gateway/gengateway/template.go index c7d3e8d91bf..57bd5210ac1 100644 --- a/protoc-gen-grpc-gateway/gengateway/template.go +++ b/protoc-gen-grpc-gateway/gengateway/template.go @@ -245,6 +245,14 @@ func Register{{$svc.GetName}}Handler(ctx context.Context, mux *runtime.ServeMux, {{range $m := $svc.Methods}} {{range $b := $m.Bindings}} mux.Handle({{$b.HTTPMethod | printf "%q"}}, pattern_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + closeNotifier, ok := w.(http.CloseNotifier) + if ok { + go func() { + <-closeNotifier.CloseNotify() + cancel() + }() + } resp, err := request_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(runtime.AnnotateContext(ctx, req), client, req, pathParams) if err != nil { runtime.HTTPError(ctx, w, req, err)