Skip to content

Commit 5a61e0f

Browse files
spboyerCopilot
andcommitted
chore: replace http.NewRequest with http.NewRequestWithContext
Ensure proper context propagation for cancellation and timeout support in all HTTP requests. The codebase already uses NewRequestWithContext in 30+ places — these are the remaining inconsistencies. Fixes #7087 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2d19fcf commit 5a61e0f

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

cli/azd/extensions/azure.ai.agents/internal/project/parser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ func registerAgent(uri, token, resourceID, ingressSuffix string) string {
10381038
}
10391039

10401040
client := &http.Client{}
1041-
req, err := http.NewRequest("POST", uri, bytes.NewBuffer(payloadBytes))
1041+
req, err := http.NewRequestWithContext(context.Background(), "POST", uri, bytes.NewBuffer(payloadBytes))
10421042
if err != nil {
10431043
fmt.Fprintf(os.Stderr, "Error creating request: %v\n", err)
10441044
continue
@@ -1103,7 +1103,7 @@ func testUnauthenticatedAccess(acaEndpoint string) {
11031103
fmt.Printf("Request Body: %s\n", string(payload))
11041104

11051105
client := &http.Client{}
1106-
req, err := http.NewRequest("POST", uri, bytes.NewBuffer(payload))
1106+
req, err := http.NewRequestWithContext(context.Background(), "POST", uri, bytes.NewBuffer(payload))
11071107
if err != nil {
11081108
fmt.Fprintf(os.Stderr, "Error creating request: %v\n", err)
11091109
return
@@ -1158,7 +1158,7 @@ func testDataPlane(endpoint, token, agentName, agentVersion string) {
11581158
fmt.Println(string(payloadBytes))
11591159

11601160
client := &http.Client{}
1161-
req, err := http.NewRequest("POST", uri, bytes.NewBuffer(payloadBytes))
1161+
req, err := http.NewRequestWithContext(context.Background(), "POST", uri, bytes.NewBuffer(payloadBytes))
11621162
if err != nil {
11631163
fmt.Fprintf(os.Stderr, "Error creating request: %v\n", err)
11641164
return

cli/azd/internal/telemetry/appinsights-exporter/transmitter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package appinsightsexporter
88
import (
99
"bytes"
1010
"compress/gzip"
11+
"context"
1112
"encoding/json"
1213
"io"
1314
"net/http"
@@ -77,7 +78,7 @@ func (transmitter *httpTransmitter) Transmit(payload []byte, items TelemetryItem
7778

7879
gzipWriter.Close()
7980

80-
req, err := http.NewRequest(http.MethodPost, transmitter.endpoint, &postBody)
81+
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, transmitter.endpoint, &postBody)
8182
if err != nil {
8283
return nil, err
8384
}

cli/azd/pkg/llm/github_copilot.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,12 @@ func isTokenExpired(expiresAt int64) bool {
385385
// newCopilotToken gets a Copilot session token using the GitHub token
386386
func newCopilotToken(githubToken string) (*tokenData, error) {
387387
client := &http.Client{}
388-
req, err := http.NewRequest("GET", "https://api.github.com/copilot_internal/v2/token", nil)
388+
req, err := http.NewRequestWithContext(
389+
context.Background(),
390+
"GET",
391+
"https://api.github.com/copilot_internal/v2/token",
392+
nil,
393+
)
389394
if err != nil {
390395
return nil, err
391396
}

cli/azd/tools/avmres/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"context"
78
"fmt"
89
"io"
910
"net/http"
@@ -190,7 +191,7 @@ func fetchGithub(
190191
repo string,
191192
path string,
192193
tag string) ([]byte, error) {
193-
req, err := http.NewRequest("GET",
194+
req, err := http.NewRequestWithContext(context.Background(), "GET",
194195
fmt.Sprintf("https://api.github.com/repos/%s/contents/%s?ref=%s", repo, path, tag), nil)
195196
if err != nil {
196197
return nil, err

0 commit comments

Comments
 (0)