@@ -340,10 +340,51 @@ func Get429BackoffTime(ctx context.Context, response *http.Response) int64 {
340340
341341type Response struct {
342342 * http.Response
343+ Self string
344+ NextPage string
345+ }
346+
347+ func (r * Response ) Next (ctx context.Context , v interface {}) (* Response , error ) {
348+ client , _ := ClientFromContext (ctx )
349+
350+ req , err := client .requestExecutor .WithAccept ("application/json" ).WithContentType ("application/json" ).NewRequest ("GET" , r .NextPage , nil )
351+ if err != nil {
352+ return nil , err
353+ }
354+
355+ return client .requestExecutor .Do (ctx , req , v )
356+
357+ }
358+
359+ func (r * Response ) HasNextPage () bool {
360+ return r .NextPage != ""
343361}
344362
345363func newResponse (r * http.Response ) * Response {
346364 response := & Response {Response : r }
365+ links := r .Header ["Link" ]
366+
367+ if len (links ) > 0 {
368+ for _ , link := range links {
369+ splitLinkHeader := strings .Split (link , ";" )
370+ if len (splitLinkHeader ) < 2 {
371+ continue
372+ }
373+ rawLink := strings .TrimRight (strings .TrimLeft (splitLinkHeader [0 ], "<" ), ">" )
374+ rawUrl , _ := url .Parse (rawLink )
375+ rawUrl .Scheme = ""
376+ rawUrl .Host = ""
377+
378+ if strings .Contains (link , `rel="self"` ) {
379+ response .Self = rawUrl .String ()
380+ }
381+
382+ if strings .Contains (link , `rel="next"` ) {
383+ response .NextPage = rawUrl .String ()
384+ }
385+ }
386+ }
387+
347388 return response
348389}
349390
0 commit comments