From 70cd267ff54683db304ebed907ea5d51e1ab2377 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Fri, 24 Feb 2023 22:07:18 -0500 Subject: [PATCH] Return 507 for UP publishers without subscribers --- server/errors.go | 4 +--- server/server.go | 7 +++---- server/server_matrix.go | 3 +++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/errors.go b/server/errors.go index 5b0797b5..5758c257 100644 --- a/server/errors.go +++ b/server/errors.go @@ -92,7 +92,5 @@ var ( errHTTPInternalError = &errHTTP{50001, http.StatusInternalServerError, "internal server error", ""} errHTTPInternalErrorInvalidPath = &errHTTP{50002, http.StatusInternalServerError, "internal server error: invalid path", ""} errHTTPInternalErrorMissingBaseURL = &errHTTP{50003, http.StatusInternalServerError, "internal server error: base-url must be be configured for this feature", "https://ntfy.sh/docs/config/"} + errHTTPInsufficientStorage = &errHTTP{50701, http.StatusInsufficientStorage, "internal server error: cannot publish to UnifiedPush topic without active subscriber", ""} ) - -// errHTTPConflictCannotPublishWithoutRateVisitor = &errHTTP{40904, http.StatusConflict, "conflict: cannot publish to UnifiedPush topic without active subscriber", ""} - diff --git a/server/server.go b/server/server.go index eb1ea91e..4486a0dc 100644 --- a/server/server.go +++ b/server/server.go @@ -581,10 +581,9 @@ func (s *Server) handlePublishWithoutResponse(r *http.Request, v *visitor) (*mes if err != nil { return nil, err } - /*if unifiedpush && t.RateVisitor() == nil { - return nil, errHTTPConflictCannotPublishWithoutRateVisitor - } else*/ - if !util.ContainsIP(s.config.VisitorRequestExemptIPAddrs, v.ip) && !vrate.MessageAllowed() { + if unifiedpush && t.RateVisitor() == nil { + return nil, errHTTPInsufficientStorage + } else if !util.ContainsIP(s.config.VisitorRequestExemptIPAddrs, v.ip) && !vrate.MessageAllowed() { return nil, errHTTPTooManyRequestsLimitMessages } else if email != "" && !vrate.EmailAllowed() { return nil, errHTTPTooManyRequestsLimitEmails diff --git a/server/server_matrix.go b/server/server_matrix.go index 2ec77546..8adac9d8 100644 --- a/server/server_matrix.go +++ b/server/server_matrix.go @@ -72,6 +72,9 @@ type matrixResponse struct { } // errMatrix represents an error when handing Matrix gateway messages +// +// If the pushKey is set, the app server will remove it and will never send messages using the same +// push key again, until the user repairs it. type errMatrix struct { pushKey string err error