@@ -1123,10 +1123,6 @@ func (c *streamableClientConn) Read(ctx context.Context) (jsonrpc.Message, error
11231123 }
11241124}
11251125
1126- // testAuth controls whether a fake Authorization header is added to outgoing requests.
1127- // TODO: replace with a better mechanism when client-side auth is in place.
1128- var testAuth = false
1129-
11301126// Write implements the [Connection] interface.
11311127func (c * streamableClientConn ) Write (ctx context.Context , msg jsonrpc.Message ) error {
11321128 if err := c .failure (); err != nil {
@@ -1144,9 +1140,6 @@ func (c *streamableClientConn) Write(ctx context.Context, msg jsonrpc.Message) e
11441140 }
11451141 req .Header .Set ("Content-Type" , "application/json" )
11461142 req .Header .Set ("Accept" , "application/json, text/event-stream" )
1147- if testAuth {
1148- req .Header .Set ("Authorization" , "Bearer foo" )
1149- }
11501143 c .setMCPHeaders (req )
11511144
11521145 resp , err := c .client .Do (req )
@@ -1192,6 +1185,10 @@ func (c *streamableClientConn) Write(ctx context.Context, msg jsonrpc.Message) e
11921185 return nil
11931186}
11941187
1188+ // testAuth controls whether a fake Authorization header is added to outgoing requests.
1189+ // TODO: replace with a better mechanism when client-side auth is in place.
1190+ var testAuth = false
1191+
11951192func (c * streamableClientConn ) setMCPHeaders (req * http.Request ) {
11961193 c .mu .Lock ()
11971194 defer c .mu .Unlock ()
@@ -1202,6 +1199,9 @@ func (c *streamableClientConn) setMCPHeaders(req *http.Request) {
12021199 if c .sessionID != "" {
12031200 req .Header .Set (sessionIDHeader , c .sessionID )
12041201 }
1202+ if testAuth {
1203+ req .Header .Set ("Authorization" , "Bearer foo" )
1204+ }
12051205}
12061206
12071207func (c * streamableClientConn ) handleJSON (resp * http.Response ) {
0 commit comments