MCPcopy
hub / github.com/cloudflare/cloudflared / wsFlakyEndpoint

Function wsFlakyEndpoint

connection/connection_test.go:179–197  ·  view source on GitHub ↗
(w ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

177}
178
179func 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
199func originRespEndpoint(w ResponseWriter, status int, data []byte) {
200 resp := &http.Response{

Callers 1

ProxyHTTPMethod · 0.85

Calls 9

CloseMethod · 0.95
NewConnFunction · 0.92
PipeFunction · 0.92
IntMethod · 0.80
DurationMethod · 0.80
WriteRespHeadersMethod · 0.65
ContextMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected