File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,16 @@ const (
1515 // DefaultAppVersion is the default app version used to communicate with the API.
1616 // This must be changed (using the WithAppVersion option) for production use.
1717 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 = ""
1822)
1923
2024type managerBuilder struct {
2125 hostURL string
2226 appVersion string
27+ userAgent string
2328 transport http.RoundTripper
2429 verifyProofs bool
2530 cookieJar http.CookieJar
@@ -33,6 +38,7 @@ func newManagerBuilder() *managerBuilder {
3338 return & managerBuilder {
3439 hostURL : DefaultHostURL ,
3540 appVersion : DefaultAppVersion ,
41+ userAgent : DefaultUserAgent ,
3642 transport : http .DefaultTransport ,
3743 verifyProofs : true ,
3844 cookieJar : nil ,
@@ -74,6 +80,7 @@ func (builder *managerBuilder) build() *Manager {
7480 // Set app version in header.
7581 m .rc .OnBeforeRequest (func (_ * resty.Client , req * resty.Request ) error {
7682 req .SetHeader ("x-pm-appversion" , builder .appVersion )
83+ req .SetHeader ("User-Agent" , builder .userAgent )
7784 return nil
7885 })
7986
Original file line number Diff line number Diff line change @@ -32,6 +32,20 @@ func WithAppVersion(appVersion string) Option {
3232 }
3333}
3434
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+
3549type withAppVersion struct {
3650 appVersion string
3751}
You can’t perform that action at this time.
0 commit comments