Skip to content

Commit 0e30f8e

Browse files
authored
feat: Set user-agent for plugin downloads (#1707)
1 parent dc85f43 commit 0e30f8e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/ext/wasm/wasm.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
wasmtime "github.com/bytecodealliance/wasmtime-go"
2222

23+
"github.com/kyleconroy/sqlc/internal/info"
2324
"github.com/kyleconroy/sqlc/internal/plugin"
2425
)
2526

@@ -129,9 +130,12 @@ func (r *Runner) loadWASM(ctx context.Context, cache string, expected string) ([
129130
body = file
130131

131132
case strings.HasPrefix(r.URL, "https://"):
132-
// TODO: Set User-agent
133-
// TODO: Set ETag
134-
resp, err := http.Get(r.URL)
133+
req, err := http.NewRequestWithContext(ctx, "GET", r.URL, nil)
134+
if err != nil {
135+
return nil, fmt.Errorf("http.Get: %s %w", r.URL, err)
136+
}
137+
req.Header.Set("User-Agent", fmt.Sprintf("sqlc/%s Go/%s (%s %s)", info.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH))
138+
resp, err := http.DefaultClient.Do(req)
135139
if err != nil {
136140
return nil, fmt.Errorf("http.Get: %s %w", r.URL, err)
137141
}

0 commit comments

Comments
 (0)