| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package lhttp | 5 package lhttp |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "errors" | 10 "errors" |
| 11 "fmt" | 11 "fmt" |
| 12 "io" | 12 "io" |
| 13 "io/ioutil" | 13 "io/ioutil" |
| 14 "net/http" | 14 "net/http" |
| 15 "net/url" | 15 "net/url" |
| 16 "os" | 16 "os" |
| 17 "strings" | 17 "strings" |
| 18 | 18 |
| 19 » "github.com/luci/luci-go/client/internal/retry" | 19 » "github.com/luci/luci-go/common/retry" |
| 20 ) | 20 ) |
| 21 | 21 |
| 22 // Handler is called once or multiple times for each HTTP request that is tried. | 22 // Handler is called once or multiple times for each HTTP request that is tried. |
| 23 type Handler func(*http.Response) error | 23 type Handler func(*http.Response) error |
| 24 | 24 |
| 25 // Retriable is a retry.Retriable that exposes the resulting HTTP status | 25 // Retriable is a retry.Retriable that exposes the resulting HTTP status |
| 26 // code. | 26 // code. |
| 27 type Retriable interface { | 27 type Retriable interface { |
| 28 retry.Retriable | 28 retry.Retriable |
| 29 // Returns the HTTP status code of the last request, if set. | 29 // Returns the HTTP status code of the last request, if set. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return fmt.Errorf("http request failed: %s (HTTP %d)", http.Stat
usText(resp.StatusCode), resp.StatusCode) | 182 return fmt.Errorf("http request failed: %s (HTTP %d)", http.Stat
usText(resp.StatusCode), resp.StatusCode) |
| 183 } | 183 } |
| 184 // The handler may still return a retry.Error to indicate that the reque
st | 184 // The handler may still return a retry.Error to indicate that the reque
st |
| 185 // should be retried even on successful status code. | 185 // should be retried even on successful status code. |
| 186 return r.handler(resp) | 186 return r.handler(resp) |
| 187 } | 187 } |
| 188 | 188 |
| 189 func (r *retriable) Status() int { | 189 func (r *retriable) Status() int { |
| 190 return r.status | 190 return r.status |
| 191 } | 191 } |
| OLD | NEW |