summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar Vyr Cossont <VyrCossont@users.noreply.github.com>2025-02-09 02:13:28 -0800
committerLibravatar GitHub <noreply@github.com>2025-02-09 11:13:28 +0100
commita6d1f5bf2c81f26200bc12cfeb61e9a2965b933e (patch)
tree26018d2e1a5b27140db512a00542dc8668f07573 /internal
parent[docs/zh] Update zh docs: synced to e10de84 (#3763) (diff)
downloadgotosocial-a6d1f5bf2c81f26200bc12cfeb61e9a2965b933e.tar.xz
[bugfix] Reduce Web Push record size (#3762)
Diffstat (limited to 'internal')
-rw-r--r--internal/webpush/realsender.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/internal/webpush/realsender.go b/internal/webpush/realsender.go
index 919cea788..363f5d8c2 100644
--- a/internal/webpush/realsender.go
+++ b/internal/webpush/realsender.go
@@ -192,6 +192,11 @@ func (r *realSender) sendToSubscription(
// while waiting for the client to retrieve them.
TTL = 48 * time.Hour
+ // recordSize limits how big our notifications can be once padding is applied.
+ // To be polite to applications that need to relay them over services like APNS,
+ // which has a max message size of 4 kB, we set this comfortably smaller.
+ recordSize = 2048
+
// responseBodyMaxLen limits how much of the Web Push server response we read for error messages.
responseBodyMaxLen = 1024
)
@@ -232,6 +237,7 @@ func (r *realSender) sendToSubscription(
},
&webpushgo.Options{
HTTPClient: r.httpClient,
+ RecordSize: recordSize,
Subscriber: "https://" + config.GetHost(),
VAPIDPublicKey: vapidKeyPair.Public,
VAPIDPrivateKey: vapidKeyPair.Private,
@@ -346,8 +352,9 @@ func formatNotificationTitle(
// or the beginning of the bio text of the related account.
func formatNotificationBody(apiNotification *apimodel.Notification) string {
// bodyMaxLen is a polite maximum length for a Web Push notification's body text, in bytes. Note that this isn't
- // limited per se, but Web Push servers may reject anything with a total request body size over 4k.
- const bodyMaxLen = 3000
+ // limited per se, but Web Push servers may reject anything with a total request body size over 4k,
+ // and we set a lower max size above for compatibility with mobile push systems.
+ const bodyMaxLen = 1500
var body string
if apiNotification.Status != nil {