Skip to content

Commit 672b39b

Browse files
henrybarretogustavosbarreto
authored andcommitted
chore(agent): rename connection handler for better meaning
1 parent 1f2d9dc commit 672b39b

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

pkg/agent/agent.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func (a *Agent) Close() error {
371371
return a.tunnel.Close()
372372
}
373373

374-
func connHandler(serv *server.Server) func(c echo.Context) error {
374+
func sshHandler(serv *server.Server) func(c echo.Context) error {
375375
return func(c echo.Context) error {
376376
hj, ok := c.Response().Writer.(http.Hijacker)
377377
if !ok {
@@ -394,8 +394,8 @@ func connHandler(serv *server.Server) func(c echo.Context) error {
394394
}
395395
}
396396

397-
// proxyHandler handlers proxy connections to the required address.
398-
func proxyHandler(agent *Agent) func(c echo.Context) error {
397+
// httpProxyHandler handlers proxy connections to the required address.
398+
func httpProxyHandler(agent *Agent) func(c echo.Context) error {
399399
const ProxyHandlerNetwork = "tcp"
400400

401401
return func(c echo.Context) error {
@@ -530,7 +530,7 @@ func proxyHandler(agent *Agent) func(c echo.Context) error {
530530
}
531531
}
532532

533-
func closeHandler(a *Agent, serv *server.Server) func(c echo.Context) error {
533+
func sshCloseHandler(a *Agent, serv *server.Server) func(c echo.Context) error {
534534
return func(c echo.Context) error {
535535
id := c.Param("id")
536536
serv.CloseSession(id)
@@ -553,9 +553,9 @@ func (a *Agent) Listen(ctx context.Context) error {
553553
a.mode.Serve(a)
554554

555555
a.tunnel = tunnel.NewBuilder().
556-
WithConnHandler(connHandler(a.server)).
557-
WithCloseHandler(closeHandler(a, a.server)).
558-
WithProxyHandler(proxyHandler(a)).
556+
WithSSHHandler(sshHandler(a.server)).
557+
WithSSHCloseHandler(sshCloseHandler(a, a.server)).
558+
WithHTTPProxyHandler(httpProxyHandler(a)).
559559
Build()
560560

561561
go a.ping(ctx, AgentPingDefaultInterval) //nolint:errcheck

pkg/agent/pkg/tunnel/tunnel.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
)
1111

1212
type Tunnel struct {
13-
router *echo.Echo
14-
srv *http.Server
15-
ProxyHandler func(e echo.Context) error
16-
ConnHandler func(e echo.Context) error
17-
CloseHandler func(e echo.Context) error
13+
router *echo.Echo
14+
srv *http.Server
15+
HTTPProxyHandler func(e echo.Context) error
16+
SSHHandler func(e echo.Context) error
17+
SSHCloseHandler func(e echo.Context) error
1818
}
1919

2020
type Builder struct {
@@ -27,20 +27,20 @@ func NewBuilder() *Builder {
2727
}
2828
}
2929

30-
func (t *Builder) WithProxyHandler(handler func(e echo.Context) error) *Builder {
31-
t.tunnel.ProxyHandler = handler
30+
func (t *Builder) WithHTTPProxyHandler(handler func(e echo.Context) error) *Builder {
31+
t.tunnel.HTTPProxyHandler = handler
3232

3333
return t
3434
}
3535

36-
func (t *Builder) WithConnHandler(handler func(e echo.Context) error) *Builder {
37-
t.tunnel.ConnHandler = handler
36+
func (t *Builder) WithSSHHandler(handler func(e echo.Context) error) *Builder {
37+
t.tunnel.SSHHandler = handler
3838

3939
return t
4040
}
4141

42-
func (t *Builder) WithCloseHandler(handler func(e echo.Context) error) *Builder {
43-
t.tunnel.CloseHandler = handler
42+
func (t *Builder) WithSSHCloseHandler(handler func(e echo.Context) error) *Builder {
43+
t.tunnel.SSHCloseHandler = handler
4444

4545
return t
4646
}
@@ -60,29 +60,29 @@ func NewTunnel() *Tunnel {
6060
return context.WithValue(ctx, "http-conn", c) //nolint:revive
6161
},
6262
},
63-
ConnHandler: func(_ echo.Context) error {
63+
SSHHandler: func(_ echo.Context) error {
6464
panic("ConnHandler can not be nil")
6565
},
66-
CloseHandler: func(_ echo.Context) error {
66+
SSHCloseHandler: func(_ echo.Context) error {
6767
panic("CloseHandler can not be nil")
6868
},
69-
ProxyHandler: func(_ echo.Context) error {
69+
HTTPProxyHandler: func(_ echo.Context) error {
7070
panic("ProxyHandler can not be nil")
7171
},
7272
}
7373
e.GET("/ssh/:id", func(e echo.Context) error {
74-
return t.ConnHandler(e)
74+
return t.SSHHandler(e)
7575
})
7676
e.GET("/ssh/close/:id", func(e echo.Context) error {
77-
return t.CloseHandler(e)
77+
return t.SSHCloseHandler(e)
7878
})
7979
e.CONNECT("/ssh/proxy/:addr", func(e echo.Context) error {
8080
// NOTE: The CONNECT HTTP method requests that a proxy establish a HTTP tunnel to this server, and if
8181
// successful, blindly forward data in both directions until the tunnel is closed.
8282
//
8383
// https://en.wikipedia.org/wiki/HTTP_tunnel
8484
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT
85-
return t.ProxyHandler(e)
85+
return t.HTTPProxyHandler(e)
8686
})
8787

8888
return t

0 commit comments

Comments
 (0)