coder / coder/websocket

Hijacking FastHTTP connection to use `coder/websocket`?

Abierto
#506 0 comentarios 0 reacciones 0 asignados Ver en GitHub
needs-info
Lenguaje dominante
Go
Estrellas
5.5k
Forks
372
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hello,

Instead of the Go standard `net/http`, I am using [FastHTTP](https://github.com/valyala/fasthttp) as my webserver, in order to upgrade to websockets using [FastHTTP websocket](https://github.com/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!

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza revisando FastHTTP's RequestCtx.Hijack y la API websocket.Accept mencionada en el issue, centrándote en cómo podría pasarse la net.Conn interceptada a la library. Determina cómo se representarían el ResponseWriter y el Request requeridos y, a continuación, verifica que un handler GET de FastHTTP pueda completar una actualización a WebSocket y atender una conexión.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
go
Área
api, backend
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.