(ctx context.Context, client HTTPRequester, url *url.URL, r ByteRange)
| 128 | } |
| 129 | |
| 130 | func (zs *Syncer) fetchRange(ctx context.Context, client HTTPRequester, url *url.URL, r ByteRange) (int64, error) { |
| 131 | req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil) |
| 132 | if err != nil { |
| 133 | return 0, err |
| 134 | } |
| 135 | req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", r.Start, r.End)) |
| 136 | resp, err := client.Do(req) |
| 137 | if err != nil { |
| 138 | return 0, err |
| 139 | } |
| 140 | defer resp.Body.Close() |
| 141 | if resp.StatusCode != http.StatusPartialContent { |
| 142 | return 0, fmt.Errorf("expected partial content from %s, got %s", url.String(), resp.Status) |
| 143 | } |
| 144 | return zs.SubmitTargetData(r.Start, resp.Body) |
| 145 | } |
no test coverage detected