| 1 | package lfshttpscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.25.0 context/" |
| 5 | "net/httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/" |
| 6 | ) |
| 7 | |
| 8 | // ckey is a type that wraps a string for package-unique context.Context keys. |
| 9 | type ckeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/ckey# string |
| 10 | |
| 11 | const ( |
| 12 | // contextKeyRetries is a context.Context key for storing the desired |
| 13 | // number of retries for a given request. |
| 14 | contextKeyRetriesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/contextKeyRetries. ckeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/ckey# = "retries" |
| 15 | |
| 16 | // defaultRequestRetries is the default number of retries to perform on |
| 17 | // a given HTTP request. |
| 18 | defaultRequestRetriesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/defaultRequestRetries. = 0 |
| 19 | ) |
| 20 | |
| 21 | // WithRetries stores the desired number of retries "n" on the given |
| 22 | // http.Request, and causes it to be retried "n" times in the case of a non-nil |
| 23 | // network related error. |
| 24 | func WithRetriesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/WithRetries().(req *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#, n int) *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request# { |
| 25 | ctx := req.Contextscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Context().() |
| 26 | ctx = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.0 context/WithValue().(ctx, contextKeyRetriesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/contextKeyRetries., n) |
| 27 | |
| 28 | return req.WithContextscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#WithContext().(ctx) |
| 29 | } |
| 30 | |
| 31 | // Retries returns the number of retries requested for a given http.Request. |
| 32 | func Retriesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/Retries().(req *httpscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#) (int, bool) { |
| 33 | n, ok := req.Contextscip-go gomod github.com/golang/go/src go1.25.0 `net/http`/Request#Context().().Valuescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Value().(contextKeyRetriesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfshttp`/contextKeyRetries.).(int) |
| 34 | |
| 35 | return n, ok |
| 36 | } |