Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 103fac6

Browse files
committedNov 23, 2015
Make closenotify work
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
1 parent 3109b59 commit 103fac6

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed
 

‎commands/http/handler.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,6 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
149149

150150
ctx, cancel := context.WithCancel(node.Context())
151151
defer cancel()
152-
if cn, ok := w.(http.CloseNotifier); ok {
153-
go func() {
154-
select {
155-
case <-cn.CloseNotify():
156-
case <-ctx.Done():
157-
}
158-
cancel()
159-
}()
160-
}
161152

162153
err = req.SetRootContext(ctx)
163154
if err != nil {
@@ -166,17 +157,28 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
166157
}
167158

168159
// call the command
169-
res := i.root.Call(req)
160+
go func() {
161+
res := i.root.Call(req)
162+
// now handle responding to the client properly
163+
sendResponse(w, r, res, req)
164+
}()
170165

171166
// set user's headers first.
172167
for k, v := range i.cfg.Headers {
173168
if !skipAPIHeader(k) {
174169
w.Header()[k] = v
175170
}
176171
}
172+
if cn, ok := w.(http.CloseNotifier); ok {
173+
select {
174+
case <-cn.CloseNotify():
175+
log.Error("closenotify")
176+
case <-ctx.Done():
177+
log.Error("done")
178+
}
179+
cancel()
180+
}
177181

178-
// now handle responding to the client properly
179-
sendResponse(w, r, res, req)
180182
}
181183

182184
func guessMimeType(res cmds.Response) (string, error) {

0 commit comments

Comments
 (0)
Please sign in to comment.