MCPcopy
hub / github.com/rclone/rclone / head

Method head

backend/http/http.go:675–697  ·  view source on GitHub ↗

head sends a HEAD request to update info fields in the Object

(ctx context.Context)

Source from the content-addressed store, hash-verified

673
674// head sends a HEAD request to update info fields in the Object
675func (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
700func (o *Object) decodeMetadata(ctx context.Context, res *http.Response) error {

Callers 2

NewObjectMethod · 0.95
ListMethod · 0.95

Calls 7

urlMethod · 0.95
decodeMetadataMethod · 0.95
MimeTypeFunction · 0.92
statusErrorFunction · 0.85
DoMethod · 0.65
ErrorfMethod · 0.45
addHeadersMethod · 0.45

Tested by

no test coverage detected