mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-17 20:25:50 +02:00
Switch from golang.org/x/net/websocket to nhooyr.io/websocket and handle NotFound errors (#105)
* Switch from golang.org/x/net/websocket to nhooyr.io/websocket * Do not attach errors that we can handle to the Gin's context * Add missing newline to "no credentials specified or found, ..." message * Fix potential NPE in ChooseUsernameAndPassword() * Fix type in PortForward() error message in "orchard ssh vm" * Fix potential NPE in Connections() * Use header.Set() for consistency's sake for Authorization header
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/cirruslabs/orchard/rpc"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/net/websocket"
|
||||
"net/http"
|
||||
"nhooyr.io/websocket"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@@ -95,11 +95,26 @@ func (controller *Controller) portForwardVM(ctx *gin.Context) responder.Responde
|
||||
// worker will asynchronously start port-forwarding so we wait
|
||||
select {
|
||||
case fromWorkerConnection := <-boomerangConnCh:
|
||||
websocket.Handler(func(wsConn *websocket.Conn) {
|
||||
if err := proxy.Connections(wsConn, fromWorkerConnection); err != nil {
|
||||
controller.logger.Warnf("failed to port-forward: %v", err)
|
||||
}
|
||||
}).ServeHTTP(ctx.Writer, ctx.Request)
|
||||
wsConn, err := websocket.Accept(ctx.Writer, ctx.Request, &websocket.AcceptOptions{
|
||||
OriginPatterns: []string{"*"},
|
||||
})
|
||||
if err != nil {
|
||||
return responder.Error(err)
|
||||
}
|
||||
|
||||
expectedMsgType := websocket.MessageBinary
|
||||
|
||||
// Backwards compatibility with older Orchard clients
|
||||
// using "golang.org/x/net/websocket" package
|
||||
if ctx.Request.Header.Get("User-Agent") == "" {
|
||||
expectedMsgType = websocket.MessageText
|
||||
}
|
||||
|
||||
wsConnAsNetConn := websocket.NetConn(ctx, wsConn, expectedMsgType)
|
||||
|
||||
if err := proxy.Connections(wsConnAsNetConn, fromWorkerConnection); err != nil {
|
||||
controller.logger.Warnf("failed to port-forward: %v", err)
|
||||
}
|
||||
|
||||
return responder.Empty()
|
||||
case <-ctx.Done():
|
||||
|
||||
Reference in New Issue
Block a user