(w ResponseWriter, r *http.Request)
| 177 | } |
| 178 | |
| 179 | func wsFlakyEndpoint(w ResponseWriter, r *http.Request) error { |
| 180 | resp := &http.Response{ |
| 181 | StatusCode: http.StatusSwitchingProtocols, |
| 182 | } |
| 183 | if err := w.WriteRespHeaders(resp.StatusCode, resp.Header); err != nil { |
| 184 | return err |
| 185 | } |
| 186 | wsCtx, cancel := context.WithCancel(r.Context()) |
| 187 | |
| 188 | wsConn := websocket.NewConn(wsCtx, NewHTTPResponseReadWriterAcker(w, w.(http.Flusher), r), &log) |
| 189 | |
| 190 | rInt, _ := rand.Int(rand.Reader, big.NewInt(50)) |
| 191 | closedAfter := time.Millisecond * time.Duration(rInt.Int64()) |
| 192 | originConn := &flakyConn{closeAt: time.Now().Add(closedAfter)} |
| 193 | stream.Pipe(wsConn, originConn, &log) |
| 194 | cancel() |
| 195 | wsConn.Close() |
| 196 | return nil |
| 197 | } |
| 198 | |
| 199 | func originRespEndpoint(w ResponseWriter, status int, data []byte) { |
| 200 | resp := &http.Response{ |
no test coverage detected