MCPcopy
hub / github.com/nats-io/nats.go / TestWSHeaders_StaticAppliedOnHandshake

Function TestWSHeaders_StaticAppliedOnHandshake

ws_test.go:736–767  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

734}
735
736func TestWSHeaders_StaticAppliedOnHandshake(t *testing.T) {
737 addr, got, closeLn := startHeaderCatcher(t)
738 defer closeLn()
739
740 static := make(http.Header)
741 static.Set("Authorization", "Bearer Random Token")
742 static.Add("X-Multi", "v1")
743 static.Add("X-Multi", "v2")
744
745 // Intentionally connect to our fake server; it won't complete the upgrade.
746 opts := GetDefaultOptions()
747 opts.WebSocketConnectionHeaders = static
748 opts.Url = "ws://" + addr
749 _, err := opts.Connect()
750 if err == nil {
751 t.Fatalf("expected connect to fail because server does not reply")
752 }
753
754 var headers []string
755 select {
756 case headers = <-got:
757 case <-time.After(2 * time.Second):
758 t.Fatal("did not capture headers in time")
759 }
760
761 if !hasHeaderValue(headers, "Authorization", "Bearer Random Token") {
762 t.Fatalf("Authorization header missing: %v", headers)
763 }
764 if !hasHeaderValue(headers, "X-Multi", "v1") || !hasHeaderValue(headers, "X-Multi", "v2") {
765 t.Fatalf("X-Multi headers missing/combined incorrectly: %v", headers)
766 }
767}
768
769func TestWSHeaders_HandlerAppliedOnHandshake(t *testing.T) {
770 addr, got, closeLn := startHeaderCatcher(t)

Callers

nothing calls this directly

Calls 7

startHeaderCatcherFunction · 0.85
GetDefaultOptionsFunction · 0.85
hasHeaderValueFunction · 0.85
ConnectMethod · 0.80
FatalfMethod · 0.80
SetMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected