Skip to content

Commit c605c8d

Browse files
committed
add done func support for tracing response writer
1 parent e83a3a4 commit c605c8d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

coderd/tracing/status_writer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type StatusWriter struct {
2727
http.ResponseWriter
2828
Status int
2929
Hijacked bool
30+
Done []func() // If non-nil, this function will be called when the handler is done.
3031
responseBody []byte
3132

3233
wroteHeader bool
@@ -37,6 +38,9 @@ func StatusWriterMiddleware(next http.Handler) http.Handler {
3738
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
3839
sw := &StatusWriter{ResponseWriter: rw}
3940
next.ServeHTTP(sw, r)
41+
for _, done := range sw.Done {
42+
done()
43+
}
4044
})
4145
}
4246

0 commit comments

Comments
 (0)