Skip to content

Commit caf9cf7

Browse files
author
Arthur Amstutz
committed
feat: Allow setting the user-agent in WASM binary + add a setter for the endpoint
Signed-off-by: Arthur Amstutz <[email protected]>
1 parent 2a15e40 commit caf9cf7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.github/workflows/golang-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
go-version: ["1.20", "1.21", "1.22"]
11+
go-version: ["1.20", "1.21", "1.22", "1.23", "1.24"]
1212

1313
steps:
1414
- uses: actions/checkout@v3

ovh/ovh.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"io/ioutil"
1212
"net/http"
13+
"runtime"
1314
"strconv"
1415
"strings"
1516
"sync/atomic"
@@ -162,6 +163,10 @@ func (c *Client) Endpoint() string {
162163
return c.endpoint
163164
}
164165

166+
func (c *Client) SetEndpoint(endpoint string) {
167+
c.endpoint = endpoint
168+
}
169+
165170
//
166171
// High level helpers
167172
//
@@ -377,7 +382,13 @@ func (c *Client) NewRequest(method, path string, reqBody interface{}, needAuth b
377382
c.Client.Timeout = c.Timeout
378383

379384
if c.UserAgent != "" {
380-
req.Header.Set("User-Agent", "github.com/ovh/go-ovh ("+c.UserAgent+")")
385+
// When running in a WebAssembly binary, let the caller set
386+
// the user-agent freely to be able to use the browser's one.
387+
if runtime.GOARCH == "wasm" && runtime.GOOS == "js" {
388+
req.Header.Set("User-Agent", c.UserAgent)
389+
} else {
390+
req.Header.Set("User-Agent", "github.com/ovh/go-ovh ("+c.UserAgent+")")
391+
}
381392
} else {
382393
req.Header.Set("User-Agent", "github.com/ovh/go-ovh")
383394
}

0 commit comments

Comments
 (0)