code: func (s *Server) wrap() {
  	oldHook := s.Config.ConnState
  	s.Config.ConnState = func(c net.Conn, cs http.ConnState) {
  		s.mu.Lock()
  		defer s.mu.Unlock()
  		switch cs {
  		case http.StateNew:
  			s.wg.Add(1)
  			if _, exists := s.conns[c]; exists {
  				panic("invalid state transition")
  			}
  			if s.conns == nil {
  				s.conns = make(map[net.Conn]http.ConnState)
  			}
  			s.conns[c] = cs
  			if s.closed {
  				// Probably just a socket-late-binding dial from
  				// the default transport that lost the race (and
  				// thus this connection is now idle and will
  				// never be used).
  				s.closeConn(c)
  			}
  		case http.StateActive:
  			if oldState, ok := s.conns[c]; ok {
  				if oldState != http.StateNew && oldState != http.StateIdle {
  					panic("invalid state transition")
  				}
  				s.conns[c] = cs
  			}
  		case http.StateIdle:
  			if oldState, ok := s.conns[c]; ok {
  				if oldState != http.StateActive {
  					panic("invalid state transition")
  				}
  				s.conns[c] = cs
  			}
  			if s.closed {
  				s.closeConn(c)
  			}
  		case http.StateHijacked, http.StateClosed:
  			s.forgetConn(c)
  		}
  		if oldHook != nil {
  			oldHook(c, cs)
  		}
  	}
  }
docs: // wrap installs the connection state-tracking hook to know which
  // connections are idle.