Skip to content

Commit a05cff4

Browse files
committed
refactor(ssh): move http request for web endpoint to target implementation
1 parent b983a75 commit a05cff4

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

ssh/http/handlers.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package http
22

33
import (
4-
"fmt"
54
"io"
65
"net/http"
76
"net/url"
@@ -110,13 +109,10 @@ func (h *Handlers) HandleHTTPProxy(c echo.Context) error {
110109
"device": endpoint.DeviceUID,
111110
})
112111

113-
// Prepare V1 CONNECT handshake request (only used if version=V1 inside target implementation)
114-
handshakeReq, _ := http.NewRequest(http.MethodConnect, fmt.Sprintf("/http/proxy/%s:%d", endpoint.Host, endpoint.Port), nil)
115112
conn, err := h.Dialer.DialTo(c.Request().Context(), endpoint.Namespace, endpoint.DeviceUID, dialer.HTTPProxyTarget{
116-
RequestID: requestID,
117-
Host: endpoint.Host,
118-
Port: endpoint.Port,
119-
HandshakeRequest: handshakeReq,
113+
RequestID: requestID,
114+
Host: endpoint.Host,
115+
Port: endpoint.Port,
120116
})
121117
if err != nil {
122118
logger.WithError(err).Error("failed to dial to device")

ssh/pkg/dialer/target.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ func (t SSHCloseTarget) prepare(conn net.Conn, version ConnectionVersion) (net.C
7777
// final HTTP request (with rewritten Host + URL) directly to the
7878
// returned connection.
7979
type HTTPProxyTarget struct {
80-
RequestID string
81-
Host string
82-
Port int
83-
HandshakeRequest *http.Request // original inbound request used for V1 CONNECT-style handshake
80+
RequestID string
81+
Host string
82+
Port int
8483
}
8584

8685
func (t HTTPProxyTarget) prepare(conn net.Conn, version ConnectionVersion) (net.Conn, error) { // nolint:ireturn
8786
switch version {
8887
case ConnectionVersion1:
8988
// Write initial handshake request and expect 200 OK.
90-
if err := t.HandshakeRequest.Write(conn); err != nil {
89+
handshakeReq, _ := http.NewRequest(http.MethodConnect, fmt.Sprintf("/http/proxy/%s:%d", t.Host, t.Port), nil)
90+
if err := handshakeReq.Write(conn); err != nil {
9191
return nil, err
9292
}
93-
resp, err := http.ReadResponse(bufio.NewReader(conn), t.HandshakeRequest)
93+
resp, err := http.ReadResponse(bufio.NewReader(conn), handshakeReq)
9494
if err != nil {
9595
return nil, err
9696
}

0 commit comments

Comments
 (0)