2 回答

TA貢獻1825條經驗 獲得超4個贊
僅通過查看加密數據無法可靠地區分“正?!盚TTP 流量和 Websockets。
人們可以通過查看流量模式來嘗試做一些啟發式方法,即在哪個方向上在哪個時間傳輸了多少數據以及數據之間有多少空閑時間。這種啟發式可以基于以下假設:HTTP 是一種請求 + 響應協議,通常小請求緊隨其后是較大的響應,而 Websockets 可以顯示任意流量模式。
但任意流量模式也意味著 Websockets 也可以以請求 + 響應的方式使用。(雖然包括請求+響應)。此外,在某些用例中,HTTP 的使用模式主要由大請求和小響應組成。因此,根據應用程序的類型,這種啟發式方法可能會成功,也可能會失敗。

TA貢獻1856條經驗 獲得超17個贊
定義全局服務器超時始終是一個好習慣,以確保資源不會永遠被鎖定。該超時不應小于所有處理程序中最長的超時。
DefaultServer = &http.Server{
Handler: http.TimeoutHandler(handler, wssTimeout, timeoutResponse),
...
}
在處理 http 和 wss 請求的 handler 中,我們需要動態設置超時時間。
func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request) {
// Request Context is going to be cancelled if client's connection closes, the request is canceled (with HTTP/2), Server we created above time outed.
// all code down the stack should respect that ctx.
ctx := r.Context()
timeoit := httpTimeout
if itIsWSS(r) {
timeout = wssTimeout
}
ctx, cancel = cWithTimeout(ctx, timeout)
defer cancel()
// all code below to use ctx instead of context.Backgound()/TODO()
- 2 回答
- 0 關注
- 131 瀏覽
添加回答
舉報