@@ -1660,52 +1660,50 @@ func (a *agent) isClosed() bool {
1660
1660
return a .hardCtx .Err () != nil
1661
1661
}
1662
1662
1663
- func (a * agent ) HTTPDebug () http.Handler {
1664
- r := chi .NewRouter ()
1665
-
1666
- requireNetwork := func (w http.ResponseWriter ) (* tailnet.Conn , bool ) {
1667
- a .closeMutex .Lock ()
1668
- network := a .network
1669
- a .closeMutex .Unlock ()
1670
-
1671
- if network == nil {
1672
- w .WriteHeader (http .StatusNotFound )
1673
- _ , _ = w .Write ([]byte ("network is not ready yet" ))
1674
- return nil , false
1675
- }
1663
+ func (a * agent ) requireNetwork () (* tailnet.Conn , bool ) {
1664
+ a .closeMutex .Lock ()
1665
+ defer a .closeMutex .Unlock ()
1666
+ return a .network , a .network != nil
1667
+ }
1676
1668
1677
- return network , true
1669
+ func (a * agent ) HandleHTTPDebugMagicsock (w http.ResponseWriter , r * http.Request ) {
1670
+ network , ok := a .requireNetwork ()
1671
+ if ! ok {
1672
+ w .WriteHeader (http .StatusInternalServerError )
1673
+ _ , _ = w .Write ([]byte ("network is not ready yet" ))
1674
+ return
1678
1675
}
1676
+ network .MagicsockServeHTTPDebug (w , r )
1677
+ }
1679
1678
1680
- r .Get ("/debug/magicsock" , func (w http.ResponseWriter , r * http.Request ) {
1681
- network , ok := requireNetwork (w )
1682
- if ! ok {
1683
- return
1684
- }
1685
- network .MagicsockServeHTTPDebug (w , r )
1686
- })
1679
+ func (a * agent ) HandleHTTPMagicsockDebugLoggingState (w http.ResponseWriter , r * http.Request ) {
1680
+ state := chi .URLParam (r , "state" )
1681
+ stateBool , err := strconv .ParseBool (state )
1682
+ if err != nil {
1683
+ w .WriteHeader (http .StatusBadRequest )
1684
+ _ , _ = fmt .Fprintf (w , "invalid state %q, must be a boolean" , state )
1685
+ return
1686
+ }
1687
1687
1688
- r .Get ("/debug/magicsock/debug-logging/{state}" , func (w http.ResponseWriter , r * http.Request ) {
1689
- state := chi .URLParam (r , "state" )
1690
- stateBool , err := strconv .ParseBool (state )
1691
- if err != nil {
1692
- w .WriteHeader (http .StatusBadRequest )
1693
- _ , _ = fmt .Fprintf (w , "invalid state %q, must be a boolean" , state )
1694
- return
1695
- }
1688
+ network , ok := a .requireNetwork ()
1689
+ if ! ok {
1690
+ w .WriteHeader (http .StatusInternalServerError )
1691
+ _ , _ = w .Write ([]byte ("network is not ready yet" ))
1692
+ return
1693
+ }
1696
1694
1697
- network , ok := requireNetwork (w )
1698
- if ! ok {
1699
- return
1700
- }
1695
+ network .MagicsockSetDebugLoggingEnabled (stateBool )
1696
+ a .logger .Info (r .Context (), "updated magicsock debug logging due to debug request" , slog .F ("new_state" , stateBool ))
1701
1697
1702
- network .MagicsockSetDebugLoggingEnabled (stateBool )
1703
- a .logger .Info (r .Context (), "updated magicsock debug logging due to debug request" , slog .F ("new_state" , stateBool ))
1698
+ w .WriteHeader (http .StatusOK )
1699
+ _ , _ = fmt .Fprintf (w , "updated magicsock debug logging to %v" , stateBool )
1700
+ }
1704
1701
1705
- w .WriteHeader (http .StatusOK )
1706
- _ , _ = fmt .Fprintf (w , "updated magicsock debug logging to %v" , stateBool )
1707
- })
1702
+ func (a * agent ) HTTPDebug () http.Handler {
1703
+ r := chi .NewRouter ()
1708
1704
1705
+ r .Get ("/debug/magicsock" , a .HandleHTTPDebugMagicsock )
1706
+ r .Get ("/debug/magicsock/debug-logging/{state}" , a .HandleHTTPMagicsockDebugLoggingState )
1709
1707
r .NotFound (func (w http.ResponseWriter , r * http.Request ) {
1710
1708
w .WriteHeader (http .StatusNotFound )
1711
1709
_ , _ = w .Write ([]byte ("404 not found" ))
0 commit comments