Split out rdp

Former-commit-id: bd53edf8e4
This commit is contained in:
Owen
2026-05-11 21:49:55 -07:00
parent 7ace4978a4
commit b72c8e643d
2 changed files with 43 additions and 38 deletions

View File

@@ -0,0 +1,43 @@
package browsergateway
import (
"net/http"
)
// Forwarding buffer size. RDP graphics traffic is bursty and TLS records cap
// at ~16 KiB, so 64 KiB lets a couple of records pile up per syscall/frame
// without wasting memory per session.
const forwardBufSize = 64 * 1024
// Config holds the configuration for a Gateway.
type Config struct {
// AuthToken is the shared secret required by RDP clients in the RDCleanPath
// ProxyAuth field, and by SSH clients as the authToken query parameter.
AuthToken string
// NativeSSH, when non-nil, configures a local PTY/shell SSH mode instead
// of proxying to an external SSH server.
NativeSSH *NativeSSHConfig
}
// Gateway is a browser-based RDP/SSH/VNC WebSocket proxy.
// Create one with New and mount it via RegisterHandlers or the individual
// HandleRDP / HandleSSH / HandleVNC http.HandlerFunc methods.
type Gateway struct {
authToken string
nativeSSH *NativeSSHConfig
}
// New creates a new Gateway from the provided Config.
func New(cfg Config) *Gateway {
return &Gateway{
authToken: cfg.AuthToken,
nativeSSH: cfg.NativeSSH,
}
}
// RegisterHandlers registers the /rdp, /ssh, and /vnc routes on mux.
func (g *Gateway) RegisterHandlers(mux *http.ServeMux) {
mux.HandleFunc("/rdp", g.HandleRDP)
mux.HandleFunc("/ssh", g.HandleSSH)
mux.HandleFunc("/vnc", g.handleVNC)
}

View File

@@ -16,44 +16,6 @@ import (
"github.com/coder/websocket"
)
// Forwarding buffer size. RDP graphics traffic is bursty and TLS records cap
// at ~16 KiB, so 64 KiB lets a couple of records pile up per syscall/frame
// without wasting memory per session.
const forwardBufSize = 64 * 1024
// Config holds the configuration for a Gateway.
type Config struct {
// AuthToken is the shared secret required by RDP clients in the RDCleanPath
// ProxyAuth field, and by SSH clients as the authToken query parameter.
AuthToken string
// NativeSSH, when non-nil, configures a local PTY/shell SSH mode instead
// of proxying to an external SSH server.
NativeSSH *NativeSSHConfig
}
// Gateway is a browser-based RDP/SSH WebSocket proxy.
// Create one with New and mount it via RegisterHandlers or the individual
// HandleRDP / HandleSSH http.HandlerFunc methods.
type Gateway struct {
authToken string
nativeSSH *NativeSSHConfig
}
// New creates a new Gateway from the provided Config.
func New(cfg Config) *Gateway {
return &Gateway{
authToken: cfg.AuthToken,
nativeSSH: cfg.NativeSSH,
}
}
// RegisterHandlers registers the /jet/rdp and /jet/ssh routes on mux.
func (g *Gateway) RegisterHandlers(mux *http.ServeMux) {
mux.HandleFunc("/rdp", g.HandleRDP)
mux.HandleFunc("/ssh", g.HandleSSH)
mux.HandleFunc("/vnc", g.handleVNC)
}
// HandleRDP is an http.HandlerFunc for RDP-over-WebSocket connections.
func (g *Gateway) HandleRDP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()