Do not set m.Expires if `cache: no` is set

pull/621/head
binwiederhier 2023-02-18 19:48:21 -05:00
parent 85fc16b016
commit 96439ac41f
4 changed files with 8 additions and 3 deletions

View File

@ -77,7 +77,7 @@ going. It'll only make ntfy better.
**Special thanks:** **Special thanks:**
A big Thank-you goes to everyone who tested the user account and payments work. I very much appreciate all the feedback, A big Thank-you goes to everyone who tested the user account and payments work. I very much appreciate all the feedback,
suggestions, and bug reports. Thank you, @nwithan8, @deadcade, @xenrox, @cmeis, and the others who I forgot. suggestions, and bug reports. Thank you, @nwithan8, @deadcade, @xenrox, @cmeis, @wunter8 and the others who I forgot.
## ntfy server v1.31.0 ## ntfy server v1.31.0
Released February 14, 2023 Released February 14, 2023

View File

@ -319,7 +319,7 @@ format of the message. It's very straight forward:
|--------------|----------|---------------------------------------------------|-------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| |--------------|----------|---------------------------------------------------|-------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| `id` | ✔️ | *string* | `hwQ2YpKdmg` | Randomly chosen message identifier | | `id` | ✔️ | *string* | `hwQ2YpKdmg` | Randomly chosen message identifier |
| `time` | ✔️ | *number* | `1635528741` | Message date time, as Unix time stamp | | `time` | ✔️ | *number* | `1635528741` | Message date time, as Unix time stamp |
| `expires` | ✔️ | *number* | `1673542291` | Unix time stamp indicating when the message will be deleted | | `expires` | () | *number* | `1673542291` | Unix time stamp indicating when the message will be deleted, not set if `Cache: no` is sent |
| `event` | ✔️ | `open`, `keepalive`, `message`, or `poll_request` | `message` | Message type, typically you'd be only interested in `message` | | `event` | ✔️ | `open`, `keepalive`, `message`, or `poll_request` | `message` | Message type, typically you'd be only interested in `message` |
| `topic` | ✔️ | *string* | `topic1,topic2` | Comma-separated list of topics the message is associated with; only one for all `message` events, but may be a list in `open` events | | `topic` | ✔️ | *string* | `topic1,topic2` | Comma-separated list of topics the message is associated with; only one for all `message` events, but may be a list in `open` events |
| `message` | - | *string* | `Some message` | Message body; always present in `message` events | | `message` | - | *string* | `Some message` | Message body; always present in `message` events |

View File

@ -589,7 +589,9 @@ func (s *Server) handlePublishWithoutResponse(r *http.Request, v *visitor) (*mes
} }
m.Sender = v.IP() m.Sender = v.IP()
m.User = v.MaybeUserID() m.User = v.MaybeUserID()
m.Expires = time.Unix(m.Time, 0).Add(v.Limits().MessageExpiryDuration).Unix() if cache {
m.Expires = time.Unix(m.Time, 0).Add(v.Limits().MessageExpiryDuration).Unix()
}
if err := s.handlePublishBody(r, v, m, body, unifiedpush); err != nil { if err := s.handlePublishBody(r, v, m, body, unifiedpush); err != nil {
return nil, err return nil, err
} }

View File

@ -149,6 +149,8 @@ func TestServer_PublishAndSubscribe(t *testing.T) {
require.Equal(t, "", messages[1].Title) require.Equal(t, "", messages[1].Title)
require.Equal(t, 0, messages[1].Priority) require.Equal(t, 0, messages[1].Priority)
require.Nil(t, messages[1].Tags) require.Nil(t, messages[1].Tags)
require.True(t, time.Now().Add(12*time.Hour-5*time.Second).Unix() < messages[1].Expires)
require.True(t, time.Now().Add(12*time.Hour+5*time.Second).Unix() > messages[1].Expires)
require.Equal(t, messageEvent, messages[2].Event) require.Equal(t, messageEvent, messages[2].Event)
require.Equal(t, "mytopic", messages[2].Topic) require.Equal(t, "mytopic", messages[2].Topic)
@ -287,6 +289,7 @@ func TestServer_PublishNoCache(t *testing.T) {
msg := toMessage(t, response.Body.String()) msg := toMessage(t, response.Body.String())
require.NotEmpty(t, msg.ID) require.NotEmpty(t, msg.ID)
require.Equal(t, "this message is not cached", msg.Message) require.Equal(t, "this message is not cached", msg.Message)
require.Equal(t, 0, msg.Expires)
response = request(t, s, "GET", "/mytopic/json?poll=1", "", nil) response = request(t, s, "GET", "/mytopic/json?poll=1", "", nil)
messages := toMessages(t, response.Body.String()) messages := toMessages(t, response.Body.String())