@@ -89,7 +89,9 @@ func TestAnthropicMessages(t *testing.T) {
8989 // Make API call to aibridge for Anthropic /v1/messages
9090 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , tc .streaming )
9191 require .NoError (t , err )
92- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
92+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
93+ require .NoError (t , err )
94+ defer resp .Body .Close ()
9395 require .Equal (t , http .StatusOK , resp .StatusCode )
9496
9597 // Response-specific checks.
@@ -220,7 +222,9 @@ func TestAnthropicMessagesModelThoughts(t *testing.T) {
220222
221223 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , tc .streaming )
222224 require .NoError (t , err )
223- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
225+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
226+ require .NoError (t , err )
227+ defer resp .Body .Close ()
224228 require .Equal (t , http .StatusOK , resp .StatusCode )
225229
226230 if tc .streaming {
@@ -258,7 +262,9 @@ func TestAWSBedrockIntegration(t *testing.T) {
258262 withCustomProvider (provider .NewAnthropic (anthropicCfg ("http://unused" , apiKey ), bedrockCfg )),
259263 )
260264
261- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , fixtures .Request (t , fixtures .AntSingleBuiltinTool ))
265+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , fixtures .Request (t , fixtures .AntSingleBuiltinTool ))
266+ require .NoError (t , err )
267+ defer resp .Body .Close ()
262268
263269 require .Equal (t , http .StatusInternalServerError , resp .StatusCode )
264270 body , err := io .ReadAll (resp .Body )
@@ -296,7 +302,9 @@ func TestAWSBedrockIntegration(t *testing.T) {
296302 // We override the AWS Bedrock client to route requests through our mock server.
297303 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , streaming )
298304 require .NoError (t , err )
299- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
305+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
306+ require .NoError (t , err )
307+ defer resp .Body .Close ()
300308
301309 // For streaming responses, consume the body to allow the stream to complete.
302310 if streaming {
@@ -419,9 +427,11 @@ func TestAWSBedrockIntegration(t *testing.T) {
419427 require .NoError (t , err )
420428
421429 // Send with Anthropic-Beta header containing flags that should be filtered.
422- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody , http.Header {
430+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody , http.Header {
423431 "Anthropic-Beta" : {"interleaved-thinking-2025-05-14,effort-2025-11-24,context-management-2025-06-27,prompt-caching-scope-2026-01-05" },
424432 })
433+ require .NoError (t , err )
434+ defer resp .Body .Close ()
425435 require .Equal (t , http .StatusOK , resp .StatusCode )
426436 _ , err = io .ReadAll (resp .Body )
427437 require .NoError (t , err )
@@ -502,7 +512,9 @@ func TestOpenAIChatCompletions(t *testing.T) {
502512 // Make API call to aibridge for OpenAI /v1/chat/completions
503513 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , tc .streaming )
504514 require .NoError (t , err )
505- resp := bridgeServer .makeRequest (t , http .MethodPost , pathOpenAIChatCompletions , reqBody )
515+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathOpenAIChatCompletions , reqBody )
516+ require .NoError (t , err )
517+ defer resp .Body .Close ()
506518 require .Equal (t , http .StatusOK , resp .StatusCode )
507519
508520 // Response-specific checks.
@@ -583,7 +595,9 @@ func TestOpenAIChatCompletions(t *testing.T) {
583595 // Add the stream param to the request.
584596 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , true )
585597 require .NoError (t , err )
586- resp := bridgeServer .makeRequest (t , http .MethodPost , pathOpenAIChatCompletions , reqBody )
598+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathOpenAIChatCompletions , reqBody )
599+ require .NoError (t , err )
600+ defer resp .Body .Close ()
587601 require .Equal (t , http .StatusOK , resp .StatusCode )
588602
589603 // Verify SSE headers are sent correctly
@@ -767,7 +781,9 @@ func TestSimple(t *testing.T) {
767781 // When: calling the "API server" with the fixture's request body.
768782 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , streaming )
769783 require .NoError (t , err )
770- resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody , http.Header {"User-Agent" : {tc .userAgent }})
784+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody , http.Header {"User-Agent" : {tc .userAgent }})
785+ require .NoError (t , err )
786+ defer resp .Body .Close ()
771787 require .Equal (t , http .StatusOK , resp .StatusCode )
772788
773789 // Then: I expect the upstream request to have the correct path.
@@ -875,11 +891,13 @@ func TestSessionIDTracking(t *testing.T) {
875891 require .NoError (t , err )
876892 }
877893
878- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody , tc .header )
894+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody , tc .header )
895+ require .NoError (t , err )
896+ defer resp .Body .Close ()
879897 require .Equal (t , http .StatusOK , resp .StatusCode )
880898
881899 // Drain the body to let the stream complete.
882- _ , err : = io .ReadAll (resp .Body )
900+ _ , err = io .ReadAll (resp .Body )
883901 require .NoError (t , err )
884902
885903 interceptions := bridgeServer .Recorder .RecordedInterceptions ()
@@ -951,7 +969,9 @@ func TestFallthrough(t *testing.T) {
951969 upstream := newMockUpstream (t .Context (), t , newFixtureResponse (fix ))
952970 bridgeServer := newBridgeTestServer (t .Context (), t , upstream .URL + tc .basePath )
953971
954- resp := bridgeServer .makeRequest (t , http .MethodGet , tc .requestPath , nil )
972+ resp , err := bridgeServer .makeRequest (t , http .MethodGet , tc .requestPath , nil )
973+ require .NoError (t , err )
974+ defer resp .Body .Close ()
955975
956976 require .Equal (t , http .StatusOK , resp .StatusCode )
957977
@@ -984,6 +1004,7 @@ func TestAnthropicInjectedTools(t *testing.T) {
9841004
9851005 // Build the requirements & make the assertions which are common to all providers.
9861006 bridgeServer , mockMCP , resp := setupInjectedToolTest (t , fixtures .AntSingleInjectedTool , streaming , defaultTracer , pathAnthropicMessages , anthropicToolResultValidator (t ))
1007+ defer resp .Body .Close ()
9871008
9881009 // Ensure expected tool was invoked with expected input.
9891010 toolUsages := bridgeServer .Recorder .RecordedToolUsages ()
@@ -1067,6 +1088,7 @@ func TestOpenAIInjectedTools(t *testing.T) {
10671088
10681089 // Build the requirements & make the assertions which are common to all providers.
10691090 bridgeServer , mockMCP , resp := setupInjectedToolTest (t , fixtures .OaiChatSingleInjectedTool , streaming , defaultTracer , pathOpenAIChatCompletions , openaiChatToolResultValidator (t ))
1091+ defer resp .Body .Close ()
10701092
10711093 // Ensure expected tool was invoked with expected input.
10721094 toolUsages := bridgeServer .Recorder .RecordedToolUsages ()
@@ -1290,7 +1312,9 @@ func TestErrorHandling(t *testing.T) {
12901312 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , streaming )
12911313 require .NoError (t , err )
12921314
1293- resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody )
1315+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody )
1316+ require .NoError (t , err )
1317+ defer resp .Body .Close ()
12941318
12951319 tc .responseHandlerFn (resp )
12961320 bridgeServer .Recorder .VerifyAllInterceptionsEnded (t )
@@ -1357,7 +1381,9 @@ func TestErrorHandling(t *testing.T) {
13571381
13581382 bridgeServer := newBridgeTestServer (ctx , t , upstream .URL )
13591383
1360- resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
1384+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
1385+ require .NoError (t , err )
1386+ defer resp .Body .Close ()
13611387
13621388 tc .responseHandlerFn (resp )
13631389 bridgeServer .Recorder .VerifyAllInterceptionsEnded (t )
@@ -1416,7 +1442,9 @@ func TestStableRequestEncoding(t *testing.T) {
14161442
14171443 // Make multiple requests and verify they all have identical payloads.
14181444 for range count {
1419- resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
1445+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
1446+ require .NoError (t , err )
1447+ defer resp .Body .Close ()
14201448 require .Equal (t , http .StatusOK , resp .StatusCode )
14211449 }
14221450
@@ -1679,7 +1707,9 @@ func TestAnthropicToolChoiceParallelDisabled(t *testing.T) {
16791707 reqBody , err := sjson .SetBytes (fix .Request (), "tool_choice" , tc .toolChoice )
16801708 require .NoError (t , err )
16811709
1682- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
1710+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
1711+ require .NoError (t , err )
1712+ defer resp .Body .Close ()
16831713 require .Equal (t , http .StatusOK , resp .StatusCode )
16841714
16851715 // Verify tool_choice in the upstream request.
@@ -1842,7 +1872,9 @@ func TestChatCompletionsParallelToolCallsDisabled(t *testing.T) {
18421872 reqBody , err = sjson .SetBytes (reqBody , "stream" , streaming )
18431873 require .NoError (t , err )
18441874
1845- resp := bridgeServer .makeRequest (t , http .MethodPost , pathOpenAIChatCompletions , reqBody )
1875+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathOpenAIChatCompletions , reqBody )
1876+ require .NoError (t , err )
1877+ defer resp .Body .Close ()
18461878 _ , err = io .ReadAll (resp .Body )
18471879 require .NoError (t , err )
18481880
@@ -1886,7 +1918,9 @@ func TestThinkingAdaptiveIsPreserved(t *testing.T) {
18861918 reqBody , err = sjson .SetBytes (reqBody , "stream" , streaming )
18871919 require .NoError (t , err )
18881920
1889- resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
1921+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
1922+ require .NoError (t , err )
1923+ defer resp .Body .Close ()
18901924 require .Equal (t , http .StatusOK , resp .StatusCode )
18911925 _ , err = io .ReadAll (resp .Body )
18921926 require .NoError (t , err )
@@ -1949,7 +1983,9 @@ func TestEnvironmentDoNotLeak(t *testing.T) {
19491983
19501984 bridgeServer := newBridgeTestServer (ctx , t , upstream .URL )
19511985
1952- resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
1986+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
1987+ require .NoError (t , err )
1988+ defer resp .Body .Close ()
19531989 require .Equal (t , http .StatusOK , resp .StatusCode )
19541990
19551991 // Verify that environment values did not leak.
@@ -2063,7 +2099,9 @@ func TestActorHeaders(t *testing.T) {
20632099 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , tc .streaming )
20642100 require .NoError (t , err )
20652101
2066- resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody )
2102+ resp , err := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody )
2103+ require .NoError (t , err )
2104+ defer resp .Body .Close ()
20672105 // Drain the body so streaming responses complete without
20682106 // a "connection reset" error in the mock upstream.
20692107 _ , err = io .ReadAll (resp .Body )
0 commit comments