Allow processing of HTTP headers at WS creation

This commit is contained in:
George Grozdev
2021-10-14 09:48:46 +01:00
parent f157dbe9d3
commit 77ac0b8e58
5 changed files with 21 additions and 9 deletions

View File

@@ -72,7 +72,7 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
}
defer conn.Close()
err = server.processWSConn(ctx, conn)
err = server.processWSConn(ctx, conn, r.Header)
switch err {
case ctx.Err():
@@ -87,7 +87,7 @@ func (server *Server) generateHandleWS(ctx context.Context, cancel context.Cance
}
}
func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) error {
func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn, headers map[string][]string) error {
typ, initLine, err := conn.ReadMessage()
if err != nil {
return errors.Wrapf(err, "failed to authenticate websocket connection")
@@ -116,7 +116,7 @@ func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) e
}
params := query.Query()
var slave Slave
slave, err = server.factory.New(params)
slave, err = server.factory.New(params, headers)
if err != nil {
return errors.Wrapf(err, "failed to create backend")
}

View File

@@ -13,5 +13,5 @@ type Slave interface {
type Factory interface {
Name() string
New(params map[string][]string) (Slave, error)
New(params map[string][]string, headers map[string][]string) (Slave, error)
}