From 014e6b4e4b85afca47f0c9cdeacecaac44dae15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Peltier?= Date: Fri, 11 Nov 2022 11:26:12 +0100 Subject: [PATCH] Add User-Agent to http request to avoid request error in some cases. --- speedtest/server.go | 4 ++++ speedtest/user.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/speedtest/server.go b/speedtest/server.go index 5701788..2687966 100644 --- a/speedtest/server.go +++ b/speedtest/server.go @@ -88,6 +88,8 @@ func (client *Speedtest) FetchServerListContext(ctx context.Context, user *User) return Servers{}, err } + req.Header.Set("User-Agent", "Go-http-client/1.1") // Request could be rejected if not initialized + resp, err := client.doer.Do(req) if err != nil { return Servers{}, err @@ -103,6 +105,8 @@ func (client *Speedtest) FetchServerListContext(ctx context.Context, user *User) return Servers{}, err } + req.Header.Set("User-Agent", "Go-http-client/1.1") // Request could be rejected if not initialized + resp, err = client.doer.Do(req) if err != nil { return Servers{}, err diff --git a/speedtest/user.go b/speedtest/user.go index 2bcc79e..46d8919 100644 --- a/speedtest/user.go +++ b/speedtest/user.go @@ -45,6 +45,8 @@ func (client *Speedtest) FetchUserInfoContext(ctx context.Context) (*User, error return nil, err } + req.Header.Set("User-Agent", "Go-http-client/1.1") // Request could be rejected if not initialized + resp, err := client.doer.Do(req) if err != nil { return nil, err