Skip to content

Commit 3505194

Browse files
committed
Make graphql compatible with go 1.7 request embeded context
1 parent 2ec20f7 commit 3505194

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

graphql/handler.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,9 @@ func NewHandler(i resource.Index) (*Handler, error) {
3434
return &Handler{schema: s}, nil
3535
}
3636

37-
// getContext creates a context for the request to add net/context support when used as a
38-
// standard http.Handler, without net/context support. The context will automatically be
39-
// canceled as soon as passed request connection will be closed.
40-
func getContext(w http.ResponseWriter, r *http.Request) context.Context {
41-
ctx, cancel := context.WithCancel(context.Background())
42-
// Handle canceled requests using net/context by passing a context
43-
// to the request handler that will be canceled as soon as the client
44-
// connection is closed
45-
if wcn, ok := w.(http.CloseNotifier); ok {
46-
notify := wcn.CloseNotify()
47-
go func() {
48-
// When client close the connection, cancel the context
49-
<-notify
50-
cancel()
51-
}()
52-
}
53-
return ctx
54-
}
55-
5637
// ServeHTTP handles requests as a http.Handler
5738
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
58-
ctx := getContext(w, r)
39+
ctx := r.Context()
5940
h.ServeHTTPC(ctx, w, r)
6041
}
6142

0 commit comments

Comments
 (0)