Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Hijack to support coder/websocket? #1930

Open
SolomonSklash opened this issue Dec 26, 2024 · 1 comment
Open

Using Hijack to support coder/websocket? #1930

SolomonSklash opened this issue Dec 26, 2024 · 1 comment

Comments

@SolomonSklash
Copy link

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!

@erikdubbelboer
Copy link
Collaborator

In theory I guess it should be possible, but I have never seen it. It requires a http.ResponseWriter and http.Request as arguments. You can try to use use fasthttpadaptor.ConvertReques() to create the http.Request, but you'll have to write your own code to convert it to a http.ResponseWriter as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants