MCPcopy
hub / github.com/coder/websocket / TestDialRedirect

Function TestDialRedirect

dial_test.go:311–334  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

309}
310
311func TestDialRedirect(t *testing.T) {
312 t.Parallel()
313
314 ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
315 defer cancel()
316
317 _, _, err := websocket.Dial(ctx, "ws://example.com", &websocket.DialOptions{
318 HTTPClient: mockHTTPClient(func(r *http.Request) (*http.Response, error) {
319 resp := &http.Response{
320 Header: http.Header{},
321 }
322 if r.URL.Scheme != "https" {
323 resp.Header.Set("Location", "wss://example.com")
324 resp.StatusCode = http.StatusFound
325 return resp, nil
326 }
327 resp.Header.Set("Connection", "Upgrade")
328 resp.Header.Set("Upgrade", "meow")
329 resp.StatusCode = http.StatusSwitchingProtocols
330 return resp, nil
331 }),
332 })
333 assert.Contains(t, err, "failed to WebSocket dial: WebSocket protocol violation: Upgrade header \"meow\" does not contain websocket")
334}
335
336type forwardProxy struct {
337 hc *http.Client

Callers

nothing calls this directly

Calls 3

DialFunction · 0.92
ContainsFunction · 0.92
mockHTTPClientFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…