File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,16 @@ const (
15
15
// DefaultAppVersion is the default app version used to communicate with the API.
16
16
// This must be changed (using the WithAppVersion option) for production use.
17
17
DefaultAppVersion = "go-proton-api"
18
+
19
+ // DefaultUserAgent is the default user agent used to communicate with the API.
20
+ // See: https://github.com/emersion/hydroxide/issues/252
21
+ DefaultUserAgent = ""
18
22
)
19
23
20
24
type managerBuilder struct {
21
25
hostURL string
22
26
appVersion string
27
+ userAgent string
23
28
transport http.RoundTripper
24
29
verifyProofs bool
25
30
cookieJar http.CookieJar
@@ -33,6 +38,7 @@ func newManagerBuilder() *managerBuilder {
33
38
return & managerBuilder {
34
39
hostURL : DefaultHostURL ,
35
40
appVersion : DefaultAppVersion ,
41
+ userAgent : DefaultUserAgent ,
36
42
transport : http .DefaultTransport ,
37
43
verifyProofs : true ,
38
44
cookieJar : nil ,
@@ -74,6 +80,7 @@ func (builder *managerBuilder) build() *Manager {
74
80
// Set app version in header.
75
81
m .rc .OnBeforeRequest (func (_ * resty.Client , req * resty.Request ) error {
76
82
req .SetHeader ("x-pm-appversion" , builder .appVersion )
83
+ req .SetHeader ("User-Agent" , builder .userAgent )
77
84
return nil
78
85
})
79
86
Original file line number Diff line number Diff line change @@ -32,6 +32,20 @@ func WithAppVersion(appVersion string) Option {
32
32
}
33
33
}
34
34
35
+ type withUserAgent struct {
36
+ userAgent string
37
+ }
38
+
39
+ func (opt withUserAgent ) config (builder * managerBuilder ) {
40
+ builder .userAgent = opt .userAgent
41
+ }
42
+
43
+ func WithUserAgent (userAgent string ) Option {
44
+ return & withUserAgent {
45
+ userAgent : userAgent ,
46
+ }
47
+ }
48
+
35
49
type withAppVersion struct {
36
50
appVersion string
37
51
}
You can’t perform that action at this time.
0 commit comments