Save the handler name for logging, see #47299-files-serving
@@ -16,6 +16,7 @@ type selectable interface {
type Selector struct {
first http.Handler
second http.Handler
+ name string
}
func NewSelector(first, second http.Handler) *Selector {
@@ -27,13 +28,25 @@ func NewSelector(first, second http.Handler) *Selector {
func (s *Selector) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if a, ok := s.first.(selectable); ok && a.hasResponse(req) {
+ if name, ok := s.first.(interface{ String() string }); ok {
+ s.name = name.String()
+ }
+
s.first.ServeHTTP(rw, req)
return
}
+ if name, ok := s.second.(interface{ String() string }); ok {
+ s.name = name.String()
+ }
+
s.second.ServeHTTP(rw, req)
}
func (s *Selector) hasResponse(req *http.Request) bool {
return true
}
+
+func (s *Selector) String() string {
+ return s.name
+}
