Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Hijacking FastHTTP connection to use `coder/websocket`?

Aperta
#506 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
go
Ambito
api, backend

Direzione di ricerca

Inizia esaminando FastHTTP's RequestCtx.Hijack e l'API websocket.Accept menzionata nell'issue, concentrandoti su come la net.Conn acquisita potrebbe essere passata alla library. Determina come verrebbero rappresentati il ResponseWriter e il Request richiesti, quindi verifica che un handler GET FastHTTP possa completare un upgrade WebSocket e servire una connessione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs-info

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/coder/websocket/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!

Lingua principale
Go
Stelle
5.5k
Fork
377
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di coder/websocket

Tutte le issue di coder/websocket

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.