Skip to content

Commit b06eaa5

Browse files
Do not overwrite the exsting Twirp headers on the context in the auth middleware (#813)
1 parent c155118 commit b06eaa5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

auth.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ package lksdk
1616

1717
import (
1818
"context"
19+
"net/http"
1920

2021
"github.com/twitchtv/twirp"
2122

2223
"github.com/livekit/protocol/auth"
24+
2325
"github.com/livekit/server-sdk-go/v2/signalling"
2426
)
2527

@@ -61,5 +63,20 @@ func (b authBase) withAuth(ctx context.Context, opt authOption, options ...authO
6163
return nil, err
6264
}
6365

64-
return twirp.WithHTTPRequestHeaders(ctx, signalling.NewHTTPHeaderWithToken(token))
66+
h := signalling.NewHTTPHeaderWithToken(token)
67+
ctxH, _ := twirp.HTTPRequestHeaders(ctx)
68+
if ctxH != nil {
69+
ctxH = ctxH.Clone()
70+
} else {
71+
ctxH = make(http.Header)
72+
}
73+
74+
// merge new header with the ones already present in the context
75+
for k, vv := range h {
76+
for _, v := range vv {
77+
ctxH.Add(k, v)
78+
}
79+
}
80+
81+
return twirp.WithHTTPRequestHeaders(ctx, ctxH)
6582
}

0 commit comments

Comments
 (0)