Skip to content

Using Hijack to support coder/websocket? #1930

@SolomonSklash

Description

@SolomonSklash

Hello,

I am trying to replace fastHTTP/websocket with coder/websocket, as it has some features I need.

Currently I use the fastHTTP/websocket upgrader like so:

func websocketUpgradeHandler(ctx *fasthttp.RequestCtx) {
	logger.Infof("Received WS request on %s", string(ctx.Path()))

	// Upgrade the connection to a websocket.
	err := websockets.Upgrader.Upgrade(ctx, func(conn *websocket.Conn) {
		// Create a new WS connection object and give it the new WS connection.
		wsConnection := &websockets.WSConnection{Conn: conn}

		// Start the inbound WS worker goroutine.
		wsConnection.WSInboundWorker()
	})
	if err != nil {
		logger.Errorf("Failed to upgrade WS connection: %s", err)
	}
}

There is a coder/websocket issue that says this is possible, via the ctx.Hijack. From what I can tell, ctx.Hijack simply exposes the underlying net.Conn. But I am unsure how to use this in conjunction with coder/websocket.

Thanks for any help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions