coder / coder/websocket

Hijacking FastHTTP connection to use `coder/websocket`?

オープン
#506 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
needs-info
主要言語
Go
スター
5.5k
フォーク
372
PR マージ指標
30日以内にマージされた PR はありません

説明

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!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、Issue で言及されている FastHTTP's RequestCtx.Hijack と websocket.Accept API を確認し、hijack された net.Conn をどのように library に渡せるかに焦点を当てます。必要な ResponseWriter と Request がどのように表現されるかを判断し、その後、FastHTTP GET handler で WebSocket upgrade を完了して接続を処理できることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
go
領域
api, backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。