Skip to content

Commit 50b917a

Browse files
authored
Merge pull request #1000 from gotify/next
fix: don't include scheme://host inside next
2 parents bd6dd76 + fdf6ce8 commit 50b917a

4 files changed

Lines changed: 13 additions & 16 deletions

File tree

api/message.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package api
33
import (
44
"encoding/json"
55
"errors"
6+
"net/url"
67
"strconv"
78
"strings"
89
"time"
910

1011
"github.com/gin-gonic/gin"
1112
"github.com/gin-gonic/gin/binding"
12-
"github.com/gotify/location"
1313
"github.com/gotify/server/v2/auth"
1414
"github.com/gotify/server/v2/model"
1515
)
@@ -104,13 +104,10 @@ func buildWithPaging(ctx *gin.Context, paging *pagingParams, messages []*model.M
104104
if len(messages) > paging.Limit {
105105
useMessages = messages[:len(messages)-1]
106106
since = useMessages[len(useMessages)-1].ID
107-
url := location.Get(ctx)
108-
url.Path = ctx.Request.URL.Path
109-
query := url.Query()
107+
query := url.Values{}
110108
query.Add("limit", strconv.Itoa(paging.Limit))
111109
query.Add("since", strconv.FormatUint(uint64(since), 10))
112-
url.RawQuery = query.Encode()
113-
next = url.String()
110+
next = ctx.Request.URL.Path + "?" + query.Encode()
114111
}
115112
return &model.PagedMessages{
116113
Paging: model.Paging{Size: len(useMessages), Limit: paging.Limit, Next: next, Since: since},

api/message_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ func (s *MessageSuite) Test_ensureCorrectJsonRepresentation() {
5252
t, _ := time.Parse("2006/01/02", "2017/01/02")
5353

5454
actual := &model.PagedMessages{
55-
Paging: model.Paging{Limit: 5, Since: 122, Size: 5, Next: "http://example.com/message?limit=5&since=122"},
55+
Paging: model.Paging{Limit: 5, Since: 122, Size: 5, Next: "/message?limit=5&since=122"},
5656
Messages: []*model.MessageExternal{{ID: 55, ApplicationID: 2, Message: "hi", Title: "hi", Date: t, Priority: intPtr(4), Extras: map[string]any{
5757
"test::string": "string",
5858
"test::array": []any{1, 2, 3},
5959
"test::int": 1,
6060
"test::float": 0.5,
6161
}}},
6262
}
63-
test.JSONEquals(s.T(), actual, `{"paging": {"limit":5, "since": 122, "size": 5, "next": "http://example.com/message?limit=5&since=122"},
63+
test.JSONEquals(s.T(), actual, `{"paging": {"limit":5, "since": 122, "size": 5, "next": "/message?limit=5&since=122"},
6464
"messages": [{"id":55,"appid":2,"message":"hi","title":"hi","priority":4,"date":"2017-01-02T00:00:00Z","extras":{"test::string":"string","test::array":[1,2,3],"test::int":1,"test::float":0.5}}]}`)
6565
}
6666

@@ -99,7 +99,7 @@ func (s *MessageSuite) Test_GetMessages_WithLimit_ReturnsNext() {
9999

100100
// Since: entries with ids from 100 - 96 will be returned (5 entries)
101101
expected := &model.PagedMessages{
102-
Paging: model.Paging{Limit: 5, Size: 5, Since: 96, Next: "http://example.com/messages?limit=5&since=96"},
102+
Paging: model.Paging{Limit: 5, Size: 5, Since: 96, Next: "/messages?limit=5&since=96"},
103103
Messages: toExternalMessages(messages[:5]),
104104
}
105105

@@ -123,7 +123,7 @@ func (s *MessageSuite) Test_GetMessages_WithLimit_WithSince_ReturnsNext() {
123123

124124
// Since: entries with ids from 54 - 42 will be returned (13 entries)
125125
expected := &model.PagedMessages{
126-
Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "http://example.com/messages?limit=13&since=42"},
126+
Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "/messages?limit=13&since=42"},
127127
Messages: toExternalMessages(messages[46 : 46+13]),
128128
}
129129
test.BodyEquals(s.T(), expected, s.recorder)
@@ -189,7 +189,7 @@ func (s *MessageSuite) Test_GetMessagesWithToken_WithLimit_ReturnsNext() {
189189

190190
// Since: entries with ids from 100 - 92 will be returned (9 entries)
191191
expected := &model.PagedMessages{
192-
Paging: model.Paging{Limit: 9, Size: 9, Since: 92, Next: "http://example.com/app/2/message?limit=9&since=92"},
192+
Paging: model.Paging{Limit: 9, Size: 9, Since: 92, Next: "/app/2/message?limit=9&since=92"},
193193
Messages: toExternalMessages(messages[:9]),
194194
}
195195

@@ -212,7 +212,7 @@ func (s *MessageSuite) Test_GetMessagesWithToken_WithLimit_WithSince_ReturnsNext
212212

213213
// Since: entries with ids from 54 - 42 will be returned (13 entries)
214214
expected := &model.PagedMessages{
215-
Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "http://example.com/app/2/message?limit=13&since=42"},
215+
Paging: model.Paging{Limit: 13, Size: 13, Since: 42, Next: "/app/2/message?limit=13&since=42"},
216216
Messages: toExternalMessages(messages[46 : 46+13]),
217217
}
218218
test.BodyEquals(s.T(), expected, s.recorder)

docs/spec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,11 +3211,11 @@
32113211
"example": 123
32123212
},
32133213
"next": {
3214-
"description": "The request url for the next page. Empty/Null when no next page is available.",
3214+
"description": "The relative path for the next page. Empty/Null when no next page is available. Should be combined with the gotify base url.",
32153215
"type": "string",
32163216
"x-go-name": "Next",
32173217
"readOnly": true,
3218-
"example": "http://example.com/message?limit=50\u0026since=123456"
3218+
"example": "/message?limit=50\u0026since=123456"
32193219
},
32203220
"since": {
32213221
"description": "The ID of the last message returned in the current request. Use this as alternative to the next link.",

model/paging.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package model
66
//
77
// swagger:model Paging
88
type Paging struct {
9-
// The request url for the next page. Empty/Null when no next page is available.
9+
// The relative path for the next page. Empty/Null when no next page is available. Should be combined with the gotify base url.
1010
//
1111
// read only: true
1212
// required: false
13-
// example: http://example.com/message?limit=50&since=123456
13+
// example: /message?limit=50&since=123456
1414
Next string `json:"next,omitempty"`
1515
// The amount of messages that got returned in the current request.
1616
//

0 commit comments

Comments
 (0)