detect CloseNotify capability in accesslog and metrics
This commit is contained in:
parent
1d4f10bead
commit
bdf4c6723f
5 changed files with 59 additions and 4 deletions
|
@ -13,6 +13,20 @@ var (
|
|||
_ middlewares.Stateful = &captureResponseWriter{}
|
||||
)
|
||||
|
||||
type capturer interface {
|
||||
http.ResponseWriter
|
||||
Size() int64
|
||||
Status() int
|
||||
}
|
||||
|
||||
func newCaptureResponseWriter(rw http.ResponseWriter) capturer {
|
||||
capt := &captureResponseWriter{rw: rw}
|
||||
if _, ok := rw.(http.CloseNotifier); !ok {
|
||||
return capt
|
||||
}
|
||||
return captureResponseWriterWithCloseNotify{capt}
|
||||
}
|
||||
|
||||
// captureResponseWriter is a wrapper of type http.ResponseWriter
|
||||
// that tracks request status and size
|
||||
type captureResponseWriter struct {
|
||||
|
@ -21,6 +35,16 @@ type captureResponseWriter struct {
|
|||
size int64
|
||||
}
|
||||
|
||||
type captureResponseWriterWithCloseNotify struct {
|
||||
*captureResponseWriter
|
||||
}
|
||||
|
||||
// CloseNotify returns a channel that receives at most a
|
||||
// single value (true) when the client connection has gone away.
|
||||
func (r *captureResponseWriterWithCloseNotify) CloseNotify() <-chan bool {
|
||||
return r.rw.(http.CloseNotifier).CloseNotify()
|
||||
}
|
||||
|
||||
func (crw *captureResponseWriter) Header() http.Header {
|
||||
return crw.rw.Header()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue