From 02ed7aa3085c5f1bb5168c5f89173abca928c4d4 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 16 Mar 2023 23:31:39 +0100 Subject: [PATCH] Set User-Agent when sending Web Push notifications This allows push servers to figure out where the notifications are coming from. --- server.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server.go b/server.go index 7cfad59..e7fdefa 100644 --- a/server.go +++ b/server.go @@ -326,6 +326,9 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap } options := webpush.Options{ + HTTPClient: &http.Client{ + Transport: userAgentHTTPTransport("soju"), + }, VAPIDPublicKey: s.webPush.VAPIDKeys.Public, VAPIDPrivateKey: s.webPush.VAPIDKeys.Private, Subscriber: "https://soju.im", @@ -733,3 +736,10 @@ func (s *Server) disableInactiveUsers(ctx context.Context) error { 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) +}