head sends a HEAD request to update info fields in the Object
(ctx context.Context)
| 673 | |
| 674 | // head sends a HEAD request to update info fields in the Object |
| 675 | func (o *Object) head(ctx context.Context) error { |
| 676 | if o.fs.opt.NoHead { |
| 677 | o.size = -1 |
| 678 | o.modTime = timeUnset |
| 679 | o.contentType = fs.MimeType(ctx, o) |
| 680 | return nil |
| 681 | } |
| 682 | url := o.url() |
| 683 | req, err := http.NewRequestWithContext(ctx, "HEAD", url, nil) |
| 684 | if err != nil { |
| 685 | return fmt.Errorf("stat failed: %w", err) |
| 686 | } |
| 687 | o.fs.addHeaders(req) |
| 688 | res, err := o.fs.httpClient.Do(req) |
| 689 | if err == nil && res.StatusCode == http.StatusNotFound { |
| 690 | return fs.ErrorObjectNotFound |
| 691 | } |
| 692 | err = statusError(res, err) |
| 693 | if err != nil { |
| 694 | return fmt.Errorf("failed to stat: %w", err) |
| 695 | } |
| 696 | return o.decodeMetadata(ctx, res) |
| 697 | } |
| 698 | |
| 699 | // decodeMetadata updates info fields in the Object according to HTTP response headers |
| 700 | func (o *Object) decodeMetadata(ctx context.Context, res *http.Response) error { |
no test coverage detected