summaryrefslogtreecommitdiff
path: root/internal/http
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-03-01 00:34:35 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2023-03-01 00:34:35 +0100
commita1519ff7685ac987f9d70b1fb49bf777028d49b0 (patch)
treeeca17170c17bb296320297e79d355a181be55866 /internal/http
parent48b669b8b37b18f6641a96d4b0986b5f1b9fef15 (diff)
Client + Exports + HTTP: Set a user-agent using the client's version
Diffstat (limited to 'internal/http')
-rw-r--r--internal/http/http.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/http/http.go b/internal/http/http.go
index 995b36f..766a2db 100644
--- a/internal/http/http.go
+++ b/internal/http/http.go
@@ -14,6 +14,9 @@ import (
"github.com/go-errors/errors"
)
+// UserAgent is the user agent that is used for requests
+var UserAgent string
+
// URLParameters is a type used for the parameters in the URL.
type URLParameters map[string]string
@@ -188,6 +191,9 @@ func (c *Client) Do(method string, urlStr string, opts *OptionalParams) (http.He
return nil, nil, errors.WrapPrefix(err,
fmt.Sprintf("failed HTTP request with method %s and url %s", method, urlStr), 0)
}
+ if UserAgent != "" {
+ req.Header.Add("User-Agent", UserAgent)
+ }
// Make sure the headers contain all the parameters
optionalHeaders(req, opts)
@@ -239,3 +245,9 @@ func (e *StatusError) Error() string {
e.Body,
)
}
+
+// RegisterAgent registers the user agent for client and version
+func RegisterAgent(client string, version string) {
+ UserAgent = fmt.Sprintf("%s/%s %s", client, version, "eduvpn-common/1.0.0")
+
+}