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

Hijacking FastHTTP connection to use coder/websocket? #506

Open
SolomonSklash opened this issue Dec 26, 2024 · 0 comments
Open

Hijacking FastHTTP connection to use coder/websocket? #506

SolomonSklash opened this issue Dec 26, 2024 · 0 comments

Comments

@SolomonSklash
Copy link

Hello,

Instead of the Go standard net/http, I am using FastHTTP as my webserver, in order to upgrade to websockets using FastHTTP websocket. It currently looks something like this, which is called by the GET handler of my FastHTTP server:

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)
	}
}

According to [#229 (https://github.com//issues/229), this should be doable with using FastHttp's fasthttp#RequestCtx.Hijack. From what I can tell, this will return the request context's underlying net.Conn object.

I am not sure how to make use of this within this websocket library. One total guess is somehow using websocket.Accept, but I don't know how to provide the required ResponseWriter and Request.

Some guidance on this would be much appreciated!

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

No branches or pull requests

1 participant