Set User-Agent when sending Web Push notifications

This allows push servers to figure out where the notifications are
coming from.
This commit is contained in:
Simon Ser 2023-03-16 23:31:39 +01:00
parent 2ce370d627
commit 02ed7aa308

View File

@ -326,6 +326,9 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
} }
options := webpush.Options{ options := webpush.Options{
HTTPClient: &http.Client{
Transport: userAgentHTTPTransport("soju"),
},
VAPIDPublicKey: s.webPush.VAPIDKeys.Public, VAPIDPublicKey: s.webPush.VAPIDKeys.Public,
VAPIDPrivateKey: s.webPush.VAPIDKeys.Private, VAPIDPrivateKey: s.webPush.VAPIDKeys.Private,
Subscriber: "https://soju.im", Subscriber: "https://soju.im",
@ -733,3 +736,10 @@ func (s *Server) disableInactiveUsers(ctx context.Context) error {
return nil return nil
} }
type userAgentHTTPTransport string
func (ua userAgentHTTPTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("User-Agent", string(ua))
return http.DefaultTransport.RoundTrip(req)
}