Skip to content

Commit

Permalink
server: remove nilRecoveryHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Sep 25, 2019
1 parent 5ddd761 commit 63560e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
12 changes: 0 additions & 12 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ import (
"resenje.org/web/recovery"
)

// Recovery handler that does not write anything to response.
// It is useful as the firs handler in chain if a handler that
// transforms response needs to be before other recovery handler,
// like compress handler.
func (s *Server) nilRecoveryHandler(h http.Handler) http.Handler {
return recovery.New(h,
recovery.WithLabel(s.Version()),
recovery.WithLogFunc(s.logger.Errorf),
recovery.WithNotifier(s.emailService),
)
}

func newRedirectDomainHandler(domain, httpsPort string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, port, _ := net.SplitHostPort(r.Host)
Expand Down
10 changes: 4 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ func New(o Options) (s *Server, err error) {
internalRouter := newInternalRouter(s)
if o.ListenInternal != "" {
s.servers.Add("internal HTTP", o.ListenInternal, httpServer.New(
s.nilRecoveryHandler(internalRouter),
internalRouter,
))
}
if o.ListenInternalTLS != "" {
s.servers.Add("internal TLS HTTP", o.ListenInternalTLS, httpServer.New(
s.nilRecoveryHandler(internalRouter),
internalRouter,
httpServer.WithTLSConfig(tlsConfig),
))
}
Expand Down Expand Up @@ -291,9 +291,7 @@ func (s *Server) WithHTTP(o HTTPOptions) (err error) {
if httpsPort != "" {
h = redirectHTTPSHandler(h, httpsPort)
}
server := httpServer.New(
s.nilRecoveryHandler(h),
)
server := httpServer.New(h)
server.IdleTimeout = idleTimeout
server.ReadTimeout = readTimeout
server.WriteTimeout = writeTimeout
Expand All @@ -306,7 +304,7 @@ func (s *Server) WithHTTP(o HTTPOptions) (err error) {

if o.ListenTLS != "" {
server := httpServer.New(
s.nilRecoveryHandler(router),
router,
httpServer.WithTLSConfig(tlsConfig),
)
server.IdleTimeout = idleTimeout
Expand Down

0 comments on commit 63560e0

Please sign in to comment.