Skip to content

Commit 05d055c

Browse files
authored
Merge pull request #850 from Pangjiping/feat/go-sdk-user-agent
feat(sdk-go): add User-Agent header to HTTP requests
2 parents 6a6f21b + 9dfd4ae commit 05d055c

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

sdks/sandbox/go/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const (
3838
// DefaultCodeInterpreterTimeoutSeconds is the default TTL for code interpreter sandboxes.
3939
DefaultCodeInterpreterTimeoutSeconds = 900
4040

41+
// Version is the SDK version reported in the User-Agent header.
42+
Version = "1.0.1"
43+
4144
// APIVersion is the lifecycle API version prefix.
4245
APIVersion = "v1"
4346

sdks/sandbox/go/execd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func (e *ExecdClient) GetCommandLogs(ctx context.Context, commandID string, curs
161161
if err != nil {
162162
return fmt.Errorf("opensandbox: create request: %w", err)
163163
}
164+
req.Header.Set("User-Agent", "OpenSandbox-Go-SDK/"+Version)
164165
for k, v := range e.client.headers {
165166
req.Header.Set(k, v)
166167
}
@@ -274,6 +275,7 @@ func (e *ExecdClient) UploadFiles(ctx context.Context, entries []UploadFileEntry
274275
}
275276
defer bodyCloser.Close()
276277

278+
req.Header.Set("User-Agent", "OpenSandbox-Go-SDK/"+Version)
277279
for k, v := range e.client.headers {
278280
req.Header.Set(k, v)
279281
}
@@ -371,6 +373,7 @@ func (e *ExecdClient) DownloadFile(ctx context.Context, remotePath string, range
371373
if err != nil {
372374
return fmt.Errorf("opensandbox: create request: %w", err)
373375
}
376+
req.Header.Set("User-Agent", "OpenSandbox-Go-SDK/"+Version)
374377
for k, v := range e.client.headers {
375378
req.Header.Set(k, v)
376379
}

sdks/sandbox/go/http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func (c *Client) doRequestOnce(ctx context.Context, method, path string, body an
143143
return fmt.Errorf("opensandbox: create request: %w", err)
144144
}
145145

146+
req.Header.Set("User-Agent", "OpenSandbox-Go-SDK/"+Version)
146147
for k, v := range c.headers {
147148
req.Header.Set(k, v)
148149
}
@@ -197,6 +198,7 @@ func (c *Client) doStreamRequest(ctx context.Context, method, path string, body
197198
return fmt.Errorf("opensandbox: create request: %w", err)
198199
}
199200

201+
req.Header.Set("User-Agent", "OpenSandbox-Go-SDK/"+Version)
200202
for k, v := range c.headers {
201203
req.Header.Set(k, v)
202204
}

0 commit comments

Comments
 (0)