Skip to content

Commit 7bb9cc2

Browse files
committed
backend: cmd/pagination: add handlePagination func to get only limited
response size this helps to get only limited number of resources that the users want to access not just fetching full resource. and then set continueToken in the proxy URL.
1 parent e96bdf4 commit 7bb9cc2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

backend/cmd/headlamp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ func clusterRequestHandler(c *HeadlampConfig) http.Handler { //nolint:funlen
13221322
if err == nil && token != "" {
13231323
r.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
13241324
}
1325+
handlePagination(r)
13251326

13261327
// Process WebSocket protocol headers if present
13271328
processWebSocketProtocolHeader(r)

backend/cmd/pagination.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import "net/http"
4+
5+
var limit string = "20"
6+
7+
// This sets limit and continueToken into the r.URL parameter
8+
// it helps to set limit and "continue" while proxying to the clusterAPI.
9+
func handlePagination(r *http.Request) {
10+
q := r.URL.Query()
11+
12+
q.Set("limit", limit)
13+
14+
continueToken := q.Get("continueToken")
15+
if continueToken != "" {
16+
q.Set("continue", continueToken)
17+
}
18+
19+
r.URL.RawQuery = q.Encode()
20+
}

0 commit comments

Comments
 (0)