Skip to content

Commit

Permalink
(Combined)LoggingHandler: Add Go 1.8 http.Pusher support
Browse files Browse the repository at this point in the history
When building with Go 1.8, embed http.Pusher interface in
loggingResponseWriter interface and define a Push wrapper method on
responseLogger.  Without this change, users of handlers.LoggingHandler
or handlers.CombinedLoggingHandler cannot take advantage of the new
http.Pusher interface since responseLogger does not satisfy the
http.Pusher interface.

When building with pre-1.8 Go, the loggingResponseWriter and
responseLogger types remain unchanged.
  • Loading branch information
Niels Widger committed Feb 9, 2017
1 parent 3a5767c commit 356173f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func makeLogger(w http.ResponseWriter) loggingResponseWriter {
return logger
}

type loggingResponseWriter interface {
type commonLoggingResponseWriter interface {
http.ResponseWriter
http.Flusher
Status() int
Expand Down
21 changes: 21 additions & 0 deletions handlers_go18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build go1.8

package handlers

import (
"fmt"
"net/http"
)

type loggingResponseWriter interface {
commonLoggingResponseWriter
http.Pusher
}

func (l *responseLogger) Push(target string, opts *http.PushOptions) error {
p, ok := l.w.(http.Pusher)
if !ok {
return fmt.Errorf("responseLogger does not implement http.Pusher")
}
return p.Push(target, opts)
}
7 changes: 7 additions & 0 deletions handlers_pre18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !go1.8

package handlers

type loggingResponseWriter interface {
commonLoggingResponseWriter
}

0 comments on commit 356173f

Please sign in to comment.