diff --git a/model/model.go b/model/model.go index b3dae915..c5278b50 100644 --- a/model/model.go +++ b/model/model.go @@ -47,6 +47,7 @@ type Message struct { PollID string `json:"poll_id,omitempty"` ContentType string `json:"content_type,omitempty"` // text/plain by default (if empty), or text/markdown Encoding string `json:"encoding,omitempty"` // Empty for raw UTF-8, or "base64" for encoded bytes + Persist *bool `json:"persist,omitempty"` // If false, clients should not save the message to local history Sender netip.Addr `json:"-"` // IP address of uploader, used for rate limiting User string `json:"-"` // UserID of the uploader, used to associated attachments } diff --git a/server/server.go b/server/server.go index 78a668bd..9eb9c828 100644 --- a/server/server.go +++ b/server/server.go @@ -1166,6 +1166,7 @@ func (s *Server) parsePublishParams(r *http.Request, m *model.Message) (cache bo } } cache = readBoolParam(r, true, "x-cache", "cache") + m.Persist = readOptionalBoolParam(r, "x-persist", "persist") firebase = readBoolParam(r, true, "x-firebase", "firebase") m.Title = readParam(r, "x-title", "title", "t") m.Click = readParam(r, "x-click", "click") diff --git a/server/util.go b/server/util.go index 305f63ea..bfc213ba 100644 --- a/server/util.go +++ b/server/util.go @@ -30,6 +30,16 @@ var ( forwardedHeaderRegex = regexp.MustCompile(`(?i)\bfor="?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[[0-9a-f:]+])(?::\d+)?"?`) ) +// readOptionalBoolParam returns nil if the param is not set, otherwise a pointer to the parsed bool value. +func readOptionalBoolParam(r *http.Request, names ...string) *bool { + value := strings.ToLower(readParam(r, names...)) + if value == "" || !isBoolValue(value) { + return nil + } + b := toBool(value) + return &b +} + func readBoolParam(r *http.Request, defaultValue bool, names ...string) bool { value := strings.ToLower(readParam(r, names...)) if value == "" {