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

Function TestWSHeaders_HandlerAppliedOnHandshake

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

Source from the content-addressed store, hash-verified

767}
768
769func TestWSHeaders_HandlerAppliedOnHandshake(t *testing.T) {
770 addr, got, closeLn := startHeaderCatcher(t)
771 defer closeLn()
772
773 provider := func() (http.Header, error) {
774 h := make(http.Header)
775 h.Set("Authorization", "Bearer FromHandler")
776 h.Add("X-Multi", "h1")
777 h.Add("X-Multi", "h2")
778 return h, nil
779 }
780
781 opts := GetDefaultOptions()
782 opts.WebSocketConnectionHeadersHandler = provider
783 opts.Url = "ws://" + addr
784 _, err := opts.Connect()
785 if err == nil {
786 t.Fatalf("expected connect to fail because server does not reply")
787 }
788
789 var headers []string
790 select {
791 case headers = <-got:
792 case <-time.After(2 * time.Second):
793 t.Fatal("did not capture headers in time")
794 }
795
796 if !hasHeaderValue(headers, "Authorization", "Bearer FromHandler") {
797 t.Fatalf("Authorization header missing: %v", headers)
798 }
799 if !hasHeaderValue(headers, "X-Multi", "h1") || !hasHeaderValue(headers, "X-Multi", "h2") {
800 t.Fatalf("X-Multi headers missing/combined incorrectly: %v", headers)
801 }
802}

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